August 31st, 2010
SharePoint 2010 has a robust modal dialog system that can be easily leveraged to build highly interactive solutions. Imaging being able to pop-up item edit forms or displaying notifications all without redirecting the user back and forth!
Here is the client side JavaScript that will allow you to open any page within a dialog box-
//Handle the DialogCallback callback
function DialogCallback(dialogResult, returnValue){
window.location = window.location;
}
//Open the Dialog
function OpenEditDialog(link){
var options = {
url:link + '&IsDlg=1',
width: 700,
height: 700,
dialogReturnValueCallback: DialogCallback};
SP.UI.ModalDialog.showModalDialog(options);
}
To invoke the dialog, simply call the OpenEditDialog function with the target URL.
Notice that the IsDlg=1 query string parameter is appended within the OpenEditDialog function. The presence of “IsDlg” dynamically loads the "/_layouts/styles/dlgframe.css” file which applies “display:none” to all items using the “s4-notdlg” css class. This effectively hides items of this class in a dialog box. For example, v4.master uses the “s4-notdlg” class for the Ribbon control to hide the ribbon within dialogs.
Tags: CSS, Javascript, SharePoint 2010, SP2010
Posted in Sharepoint 2010 (SPS / Foundation) | No Comments »
July 20th, 2010
The Microsoft.SharePoint.Utilities namespace contains a class called ThmxTheme which gives us some nice utility methods to interact with site themes in SharePoint 2010. Here is an example of how to automatically set the theme for a newly created SPWeb to be the same as the root web-
ThmxTheme.SetThemeUrlForWeb(newWeb, ThmxTheme.GetThemeUrlForWeb(newWeb.Site.RootWeb));
Do you know of a nicer way to inherit site themes? Please post a comment below.
Tags: Object Model, Programatically, SharePoint 2010, Site Theme, SP2010
Posted in Sharepoint 2010 (SPS / Foundation) | No Comments »
July 12th, 2010
Problem
Unable to make changes to the title field when declaring a content type in SharePoint 2010. For example, the following declaration has NO EFFECT on the title field being required-
<ContentType ID="0x010092E61E2438E84353B7211741448DE18A"
Name="Example"
Inherits="TRUE"
Version="0">
<FieldRefs>
<RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="FALSE" />
Workaround
Attach a feature receiver to your content type and use the object model to modify the Title field-
SPContentType contentType =
site.RootWeb.ContentTypes[
new SPContentTypeId(contentTypeId)];
SPFieldLink title = contentType.FieldLinks["Title"];
title.Required = false;
contentType.Update(true);
Discussion
This is a ‘cheap’ solution so to speak because modifying the content type via the object model disconnects it from the XML definition thus making future updates messier (Read More).
I’m a strong advocate of doing things declaratively and this solution clearly violates that rule. A colleague of mine made a case for writing content types completely non-declaratively using the object model.
What best practices do you follow when writing content types?
Tags: Content Type, SharePoint 2010, SP2010
Posted in Sharepoint 2010 (SPS / Foundation) | No Comments »
May 26th, 2010
Problem
An error related to feature activation is generated when deploying a sharepoint wsp package using visual studio 2010’s default deployment configuration -
Error occurred in deployment step ‘Activate Features’
Workaround 1
Use the “No Activation” deployment configuration and use Post-deployment command-line operations to manually activate your features since the retraction process will deactivate your features regardless.
Workaround 2
Deploy using default configuration until you see error message. Then manually Enable/Disable problem features and then RE-DEPLOY using default configuration-
1) Enable-SPFeature -identity "FeatureTitle" -Url http://localhost
2) Disable-SPFeature -identity "FeatureTitle" -Url http://localhost
Tags: Activate, Deploy, Feature, Package, Retract, SharePoint 2010, Visual Studio 2010, WSP
Posted in Sharepoint 2010 (SPS / Foundation), Visual Studio 2010 | No Comments »
May 6th, 2010
Problem
STP list templates uploaded using a feature are not available to instantiate on create.aspx
Solution
When you upload a list template (STP) using a feature to the list template gallery ( _catalogs/lt ), you must set some attributes in order for the template to show up on the create.aspx page-
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Url="_catalogs/lt" Name="PS.AACP.Stp" Path="">
<File Url="StpTest.stp" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
<Property Name="Title" Value="StpTest" />
<Property Name="Language" Value="1033" />
<Property Name="FeatureID" Value="{D90095AD-86D4-4e55-AE28-119E21530552}" />
</File>
</Module>
</Elements>
Tags: Create.aspx, Feature, File, List Template Gallery, Module, Property, STP
Posted in Sharepoint 2007 ( MOSS / WSS ) | No Comments »
May 3rd, 2010
SharePoint 2010 doesn’t directly apply a site theme but instead generates its own colors based upon the theme. Let me explain by example-
The default top navigation bar in SharePoint 2010 uses ‘Accent 1’ from the site theme to determine the background color for each one of the navigation items. However, SharePoint doesn’t directly use the user-provided hex code for this accent. Instead, there seems to be some sort of a ‘normalizing’ algorithm that generates a new hex code.
1) Let us set the Accent 1 color for our site theme to Red (#FF0000):
2) Now inspect the global top navigation bar and what you’ll notice is that the background color is NOT what you would have expected. SharePoint interpreted the red accent and generated its own hex code: #FFA5A5

Conclusion
SharePoint doesn’t directly use ‘Site Themes’ but instead seems to generate its own interpretations based upon it. Therefore, designers looking for some discreet control over the branding of a SharePoint site need to still write custom CSS in 2010.
Tags: Office Theme, s4-toplinks, SharePoint 2010, Site Theme
Posted in Sharepoint 2010 (SPS / Foundation) | No Comments »
February 26th, 2010
In order to do site specific search (a.k.a. “This Site” scope) you can append a query string parameter as follows-
http://server/results.aspx?k=sharepoint&u=http%3A%2F%2Fserver%2Flists
Problem
The above will return zero results if you have a server name mapping configured in your search settings-
Solution
Removing the server name mapping will resolve this issue and site specific search works as expected
Tip: Adding a query string url restriction is equivalent to the following-

Posted in Sharepoint 2007 ( MOSS / WSS ) | No Comments »