Tuesday, December 21, 2010

Best practise of writing code in SharePoint pages



Sunday, December 19, 2010

Create a sharepoint feature for deploying Pages in Page library

When ever we create a Share Point feature we require two file i.e., feature.xml and element.xml file.

Element.XML: (define which pages which needs to copy into page library)


Feature.XML: (create a feature for the element.xml file i.e, for the pages to copy in page library)


Thursday, September 16, 2010

Jquery is not working with the combination of UpdatePanel

I am using the Jquery get some effects for elements. The added Jquery code for element is not working because it is placed inside the update panel.
Inorder to run the Jquery in the Update panel we need to write the below code

var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function() { // re-bind your jquery events here

});

Hope this will help you.

Wednesday, July 14, 2010

SharePoint WebPart life cycle

Life Cycle of sharepoint Webparts:


1. Protected override void OnInit(EventArgs e)


OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part.


2. Protected override void OnLoad(EventArgs e)


OnLoad

User Generated Event – for e.g. button click on the web part.


3. Protected override void CreateChildControls()


CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.


4. Protected override void LoadViewState(object savedState) //Only at Postback


LoadViewState – The view state of the web part is populated over here.


5. protected override void OnPreRender(EventArgs e)


OnPreRenderHere we can change any of the web part properties before the control output is

drawn.


6. protected override void Render(System.Web.UI.HtmlTextWriter writer)


RenderContents – Html Output is generated.


7. protected override void OnUnload(EventArgs e)
8. public override void Dispose()

Friday, March 19, 2010

C# Programmatically Set audiance permissions for Sharpoint Quick launch bar

To add the links in the left navigation first we need to get all links in the quick launch bar using SPNavigationCollection class

SPWeb web = SPContext.Current.Web;
SPNavigationCollection coll = web.Navigation.QuickLaunch;

/* With SPNavigationNode class we are adding our custom links(Node) in the quick launch bar */

SPNavigationNode node = new SPNavigation(linkTitle,url,true);
/*Add the node as root in the quick launch bar*/
web.AllowUnSafeUpdates = true;
coll.AddAsFirst(node);
/*Give permissions to the link*/
node.Properties.Add("Audiance",";;;;","groupName or UserName");
node.Update();

/* Creating sub links under main links in quick launch bar */
SPNavigation subnode = new SPNavigation(linkSubTitle, subUrl,true);
node.Children.AddAsLast(subNode);
/* Providing permssions to sub links in quick launch */
subNode.Properties.Add("Audiance",";;;;","group or username");
subNode.Update();
web.AllowUnSafeUpdates = false;

thats all !!!!

Thursday, February 25, 2010

C# Copy the Permissions from one list to another list in SharePoint

Today I have got a requirement to copy the permission from existing list and Create a new list with the permissions inherited from existing list programmatically.

Here is code which is very simple will make you better understanding .

using (SPSite spSite = new SPSite("http://servername:Portnumber/"))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
SPList spList = spWeb.Lists["AgeRating"];

//Get all roles from the existing list
SPRoleAssignmentCollection coll = spList.RoleAssignments;

SPListCollection lists = spWeb.Lists;

// create new Generic list called "MyList"

if (!spWeb.Lists.Cast().Any(list => string.Equals(list.Title, "MyList")))
{
spWeb.AllowUnsafeUpdates = true;
lists.Add("MyList", "My list Description", SPListTemplateType.GenericList);
spWeb.AllowUnsafeUpdates = false;
}

SPList targetList = spWeb.Lists["MyList"];
foreach (SPRoleAssignment role in coll)
{
targetList.BreakRoleInheritance(false);
spWeb.AllowUnsafeUpdates = true;
targetList.RoleAssignments.Add(role);
}

spWeb.AllowUnsafeUpdates = false;
}
}

Thursday, February 4, 2010

Install Windows media player in Windows Server 2008 R2 server

If your Windows server 2008 r2 operating system didn't find the Windows media player installed. Please follow the below steps how to add the feature

1)Go to Start --> Administration tools --> server manger

2)Click features --> click on Add Features --> Select the "Desktop Experience"



3)Complete the wizard and restart the PC.

Looks cool right...