Thursday, October 21, 2010

Unique Permissions in SharePoint 2010 List

Have you ever wondered how to manage the permissions of a list in C# on a SharePoint list? here's you solution. It's pretty simple really. Just do the following.

FYI, if you want to do this on a list item, just iterate through each item of you list until you find the one you want and you'll find the HasUniquePermissions, BreakRoleInheritance, and RoleAssignments there too. Just treat them the same way you treat the list below.



//Here we get our context
SPContext context = SPContext.Current;

//We define a new role assignment using a login name. You could do this by email if you like, or using any of the other fields avaliable.
SPRoleAssignment ra = new SPRoleAssignment("DOMAIN\\userName", "", "", "");
//Here we assign the permission we are going to give the RA. In this case, I'm using read, but it can be any of the permission levels you have stored in SharePoint.
ra.RoleDefinitionBindings.Add(context.Web.RoleDefinitions["Read"]);

//We get our list instance.
SPList list = context.Web.Lists["List Name"];

//We check if this list has unique permissions.
if (!list.HasUniqueRoleAssignments)
{
//If it doesn't, we make it have unique permissions here. Pass true to copy from parent, false to start with clean permissions.
list.BreakRoleInheritance(false);
}

//We now add our RA
list.RoleAssignments.Add(ra);

//Update the list to save it to SharePoint
list.Update();

Monday, October 11, 2010

Install SharePoint 2010 on Vista or Windows 7

All I will say is that it works!!!

http://msdn.microsoft.com/en-us/library/ee554869(v=office.14).aspx

I did it with SharePoint Foundation. The only thing I had to change was on the extract command, I typed.

c:\SharePointFiles\SharePointFoundation.exe /extract:c:\SharePointFiles

This is awesome since creating a 64 bit VM for Windows Server 2008 is hard to come by, especially if you don't have an MSDN subscription.

Do this on your 64bit Windows 7 machine (or vista) today and start playing with SharePoint 2010. You won't be disappointed.

Saturday, October 9, 2010

SharePoint 2010 WebPart Page doesn't show Quick Launch!!! Here's how to fix it...

Have you ever had the issue when you create a new WebPart page that the quick launch bar doesn't show up? Well, this post is for you if you are trying to get it to show up.

Unfortunately, the only way I've found to get this showing is to edit the page in SharePoint designer. This is a free tool so download it if you don't have it already!

Here's what you need to get rid of to show the quick launch menu.

First, edit the page in advanced mode by right clicking the file and saying "Edit page in advanced mode"

You will now need to search for the following items in code view and delete them (or comment them out, which ever you feel comfortable with).




<SharePoint:UIVersionedContent ID="WebPartPageHideQLStyles" UIVersion="4" runat="server">
<ContentTemplate>
<style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}
</style>
</ContentTemplate>
</SharePoint:UIVersionedContent>


AND



<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>

Save you page and now the left nave will show up!!! This was confusing for me, because in the old version of SharePoint, the last step was good enough to make it visible.

Trouble with accessing Data Sheet View? Try this...

I was trying to use DataSheet view and I got this error message.

The list cannot be displayed in DataSheet view for one or more of the following reasons:

- A datasheet component compatible with Miicrosoft Sharepoint Foundation is not installed.
- Your web browser does not suport ActiveX controls
- A component is not propelry configured for 32- or 64-bit support.


What to do? Well, I sat here for a couple of hours trying to figure this out and I stumbled accross the "Access Data Engine" which is needed for the browser to show you information in datasheet view. 25 megs (roughly), but after the installation, restart your browser and all will work!

http://download.microsoft.com/download/f/d/8/fd8c20d8-e38a-48b6-8691-542403b91da1/AccessDatabaseEngine.exe