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

Monday, September 27, 2010

Is STSADM not in your path? Here's how to get it there...

Not trying to be all fancy about this, but if you found this blog item because of searching, it's because you don't know where it's at, or you do and just want to use it in Command Line without having to browse to the 12 or 14 hive.

Type the following into command line on your SharePoint server and STSADM will be in your path.

SharePoint 2010
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN;%PATH%

SharePoint 2007
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%

How long do you want the "New Item" flag to show?

I was asked by my customer a few days ago to make the "New Item" flag show for 30 days. After looking and LOOKING, no luck. I finally found my answer a few hours ago! Here's how you do it.

This works in both SharePoint 2010 and 2007.

Open up command line and make sure STSADM is in your path.

Now, type the following

stsadm -o setproperty -propertyname days-to-show-new-icon -propertyvalue 30 -url http://mysite/

You can make the amount as much as you like, so don't think you have to choose 30 days as your value too.

Saturday, September 25, 2010

The "Down To Earth" upgrade plan to 2010

So, let's say you're like me and you have a windows 2000 server, 32 bit processor. You probably don't have the basic memory requirements either to run SharePoint 2010. Now, let's say your customer pulls a fast one on you and says that they "want you to upgrade to SharePoint Foundation 2010 from WSS 3.0". What's the steps you should follow?! Well, there's two and I'm going to tell you what's documented in the MSDN articles, but in a way that's easier to understand.

Note: I'm talking about upgrading to 2010 from 2007, from a server with 32 bit processor to a server with 64 bit, if you already have a 64 bit machine that meets the requirments of SP 2010, you are already good to go! Just upgrade your package (follow the instructions listed below)

Prepare your new 64 bit server(s):
  1. First, acquire a new VM or physical box that meets the requirments documented here (http://technet.microsoft.com/en-us/library/cc288751.aspx)
  2. After you get your box set up with Windows, install WSS 3.0 x64 (http://www.microsoft.com/downloads/en/details.aspx?FamilyId=9FB41E51-CB03-4B47-B89A-396786492CBA&displaylang=en)
  3. If you are configuring as a farm, repeat these steps on both boxes.
Configure the 64 bit version of WSS 3.0 on the new box
  1. Now, once you have configured SharePoint the way your company (or you) wants it, you need to create a new web application on port 80. Delete the default one, and create a new one. Don't create a site collection on it now.
  2. Go to your old box and create a backup using STSADM by opening up command line with STSADM in the path and typing stsadm -o backup -url -filename "c:\SPBackups\backup.bak"
  3. After this completes, you need to copy that file to your new server and open command line with the STSADM in the path and type stsadm -o restore -url -filename "c:\SPBackups\backup.bak"
  4. Once the restore completes, check your site and make sure your master pages still render right and verify that your settings have copied over. You shouldn't have to change much to get this working, if you have to change anything at all.
Upgrade WSS 3.0 to SharePoint 2010
  1. Now, we have a mirror copy of our sites. Download SharePoint Foundation 2010 (or SharePoint Server 2010) and install on that box. It should upgrade you to the new server code and get you in order.
  2. After this is complete, you will need to, again, verify that all your content still renders.
There you go!!! You've now successfully installed SharePoint 2010.

I learned about this approach AFTER I did this the hard way. I kick myself to realize I could have gone this route and saved myself A LOT of time. I'm interested in hearing how you have upgraded to SharePoint 2010, also to see if anyone has done it this way and any of their problems going this route.