Simple Custom Group Assignments in SharePoint

Deploying the Web Part

All that is left to do is deploy your Web Part to your SharePoint environment and add it to a page to see it in action. In order to deploy the web part, you need to either:

Add the assembly to the global assembly cache (GAC) on your SharePoint server(s); this method requires that the assembly be strongly named

Add the assembly to the bin folder within the virtual directory for your web application(s)

I am going to use the second option during this article.

The simple and easiest way to ensure that you always have the latest version of the DLL(s) from your Web Part in the bin folder for your SharePoint web application is to add the appropriate folder to the Output Path property of your Visual Studio project. In order to do so:

Right-click the project name in your Solution Explorer from within Visual Studio

Click the Build tab

In the Output section, enter the location for your application's bin folder in the Output path property (If you do not know the location of your web application, you can get it from the IIS Admin interface)

The next step is to add a SafeControl entry in the configuration file (web.config) for your SharePoint web application. In Windows Explorer, browse to the location of the files for your web application. By default, it will look similar to this: C:\intepub\wwwroot\wss\VirtualDirectories\<<ApplicationNameandPort>>. Web.config is located in the root folder for the web applicaiton. Open it in a text editor and find the <SafeControls> section.

The easiest way to add a new safe control is to just copy the tag from the last SafeControl in the list already and modify it for your web part. In this case, your SafeControl tag should like almost exactly like this, depending on whether or not you used a different name for your Assembly and/or Namespace:

While you have web.config open, you should also ensure that you have the correct setting for the trust property. Since our web part is going to be using the SharePoint Object Model, we need to have a trust level of WSS_Medium. Your trust tag should look like this:

<trust level="WSS_Medium" originUrl="" />

Save web.config, run an iisreset and you should be ready to add your web part to your SharePoint site collection.

Configuring Your Site Collection to Use the Web Part

Now that you have finished deploying the web part, you need to add it to the Web Part Gallery of your web application's top-level site collection.

Browse to the top-level site of your web application

Click on Site Actions then "Site Settings"

In the Galleries column, click on Web Parts

In the Web Part Gallery, click on the New button

Find your new Web Part on the list, click the check box to its left and click the Populate Gallery button

Now your web part is ready to use on any web part page in your site collection.

Using Your Web Part

Here are the steps for adding the web part to a web part page.

Navigate to the web part page where you would like to add the web part

Click Site Actions then Edit Page

Within the Web Part Zone where you would like to add the Web Part, click the Add a Web Part button at the top of the Web Part Zone

Find your new web part, click the check box to its left and click the Add button

Because our web part is running with elevated priviledges, we only want to allow certain users to use the web part. Luckily, every SharePoint web part comes along with this functionality in the form of audience targeting. In order to implement audience targeting for your web part, click the edit button in the upper right corner of your web part and select Modify Shared Web Part. On the Task Pane, expand the Advanced node, scroll all the way to the bottom and use the Target Audiences control to add in the user(s) / group(s) that you want to be able to use this web part.

You may also want to control access at the page level. This makes the most sense if you want to combine this web part with some others into an Admin Console for your distributed content managers to accomplish certain Administrative tasks without giving them access to perform other things when you are not comfortable with them doing so.

Conclusion

You may have noticed that there are a few things missing here that you would most certainly want to incorporate into a production system, but those should be relatively simple for a programmer. Hopefully, if you have not worked with this kind of a customization in SharePoint before, you can use this article as a good starting point.

About the Author

Joe Mack is a Knowledge Management Evangelist and SharePoint Solution Architect, Consultant and Programmer. He has been working with SharePoint for over 6 years and has over 50 successful SharePoint implementations under his belt. He blogs at The Mack Page, tweets under mack247 and can usually be found at a client site somewhere in the world trying to proliferate his special brand of Knowledge Management, SharePoint, Business Transformation and/or Business Intelligence insanity.

He is a graduate of The United States Military Academy at West Point and lives in Indianapolis with his family.

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.