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...