Sunday, January 24, 2010

DoesUserHavePermissions ?

I just finished writing a web part that I wanted to put on the home page of the Colorado SharePoint Users Group site (http://www.cospug.com). The web parts primary function is to allow people with the appropriate permission to use it to enter a Tweet into a special list that I made that will send tweets to Twitter. I wanted to use the permissions of the list to control if the user saw the web part or not. I found the 'DoesUserHavePermissions' and thought this would be a slam dunk, but when I used it, I found that if the user didn't have the appropriate permissions, it would throw up an 'Access Denied' page instead of returning a Boolean value of 'False'. After some thinking, I decided to use the 'RunWithElevatedPrivileges' and run this code inside a privileged delegate. This was the missing element. Works like a charm now.

Saturday, January 23, 2010

Adding Assembies To SharePoint 2010 .WSP

I decided to commit most of my day today writing a series of web parts for SharePoint 2010 that would update Twitter in a variety of ways. The first web part I created did a direct update. The second one I did, wrote to a list and the list updated Twitter. I like the idea of the list update because now the Colorado SharePoint Users Group site (www.cospug.com) can now use workflows to update this list from our events calendar and announcements.

When I went to deploy the project on the server, I noticed that my TwitterAPI .dll was not included in the package. All of my SharePoint 2007 development used the WSP Builder utility that allowed you to create the package any way you wanted by using the 12 hive folder structure.

In 2010, using Visual Studio 2010, we don’t have that luxury. While most of the things I did today were fairly intuitive through the interface, packaging up the .dll files the way I wanted to took me a little longer that I had planned. I tried modifying the various manifest files that are in the project, but each of these are auto generated when you build the solution.

While I was meddling around, I started poking around the ‘Package’ folder and found that under the advanced options, I would add ‘Additional Assemblies’. Once I did that, the package was exactly the way I wanted it and I had a successful deployment.
I think I would still prefer the way WSPBuilder works, but I can’t complain much. My overall efforts in 2010 are far less than anything in 2007. Visual Studio 2010 and SharePoint 2010 make it fun to develop!!!