Home > Blog
August 31
How to leverage SharePoint 2010 dialogs?

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.

August 27
Applying Site Templates Programmatically in SharePoint 2010
Applying Site Templates Programmatically in SharePoint 2010
In previous versions of SharePoint, applying a site template (STP) to a new site through the object model was just a matter of referencing the template by its filename.
 
code1.jpg
In SharePoint 2010, site templates are stored and referenced a little bit differently. When saving a site as a template, the site is packaged as a WSP and stored in the site collection solution gallery. The contents of the template are different from STP’s which is why they are not compatible and you must re-save all your templates when migrating to SharePoint 2010.
solution.jpg

Attempting to apply a template by name no longer works and you will receive an error saying the template cannot be found. The reason being that template names are now stored with a GUID that is unique to the site collection where the template resides. NOTE: The GUID is not the same as the Solution Id that you see above. The easiest way I’ve found so far to determine the template name is to use a PowerShell script.

Script:
Add-pssnapin Microsoft.Sharepoint.PowerShell
$site = get-spsite “http://server.url” //Replace with your URL
$site.GetWebTemplates(1033) | format-table name

After running the script, you should get output that looks like the following.
templatescript.jpg
This is the template name that you must use when applying the template to a new site.

code2.jpg
One thing that I’m still looking into is deploying site template solutions globally. In 2007 it was a simple command:
·         stsadm –o addtemplate –filename ProjectTemplate.stp –title “Project Template”
However, in 2010 this command no longer works and I have yet to find some type of global solution gallery in which to deploy. Adding the solution via stsadm –o addsolution does not seem to work either. I will update this post if I find another way.
1 - 2Next

All Rights Reserved, © 2010 Portal Solutions, LLC