Tuesday, June 21, 2011

Open modal dialog (lightbox) with a hyperlink in SharePoint 2010


A new feature of SharePoint 2010 is the modal dialog which resembles the classic Light Box behavior. This allows us to add and edit items, manage Meta data and perform administrative tasks within the context of a page without leaving the page.

In just two simple steps we can implement this.
Step1:
In your Master page/aspx page add this tag for java script function to be called. For me I have added this in my master page.

script type="text/javascript">
var options = {
url: "/Lists/Announcements/NewForm.aspx", //Add your url u want to redirect your link to
title: "Add New Announcement", //Add title to your pop up window
allowMaximize: true,
showClose: true,
width: 625,
height: 525,
dialogReturnValueCallback: silentCallback
};
function open()
{
SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallback(dialogResult, returnValue)
{

}
function refreshCallback(dialogResult, returnValue)
{
SP.UI.Notify.addNotification('Operation Successful!');
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
/script>


Step2:
Add this href anchor tag on link you want to create.

a href="javascript:open()">Click Here
:) Happy Coding

Thursday, June 9, 2011

Create Blog sub site programmatically and set permissions of its parent site


public SPWeb Add(
string strWebUrl,
string strTitle,
string strDescription,
uint nLCID,
string strWebTemplate,
bool useUniquePermissions,
bool bConvertIfThere
)

Parameters

strWebUrl
Type: System.String

A string that contains the new website URL relative to the root website in the site collection. For example, to create a website at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a website one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.


strTitle
Type: System.String

A string that contains the title.


strDescription
Type: System.String

A string that contains the description.


nLCID
Type: System.UInt32

A 32-bit unsigned integer that specifies the locale ID.


strWebTemplate
Type: System.String

A string that contains the name of the site definition configuration or site template.
By default, a global site template (GLOBAL#0) is added to all site definitions. You cannot explicitly create a site based on a global site template.


useUniquePermissions
Type: System.Boolean

true to create a subsite that does not inherit permissions from another site; otherwise, false .


bConvertIfThere
Type: System.Boolean

true to convert an existing folder of the same name to a SharePoint site. false to throw an exception that indicates that a URL path with the specified site name already exists.



E.g.: For
Public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = properties.Feature.Parent as SPWeb;
CreateBlogSubsite(web);
}
catch (Exception ex)
{
}
}

private void CreateBlogSubsite(SPWeb site)
{

//useUniquePermissions true to create a subsite that does not inherit permissions from another //site; otherwise, false.

using (SPWeb blog = site.Webs.Add(strWebUrl,strTitle,strDescription,nLCID,
strWebTemplate,useUniquePermissions,bConvertIfThere,false, false))
{
blog.Update();
}
}