Add Safe Control Entries to SharePoint 2010 Web Parts using VS2010

I was reviewing a SharePoint solution and found that a web part inside that solution has poor naming conventions so I decide to rename the web parts for giving the proper names to them.

I changed the necessary references in different files of web part (I’ll mention them in a separate blog post). Now after renaming the web part I deployed it on site and then tried to add it in a web part page and it simply throws me the error.

Type is not registered as safe“. Well at first glance I decided to see me safe controls entries inside my site’s web.config file and I was right that namespace part was wrong in web.config file. It was pointing to earlier namespace and class name. Humnnnn so if I changed this entry manually then it works fine but I need to automate the deployment process and I wanted to write the correct safe controls entries inside web.config whenever we deploy the web part. Well so question arises where to set my safe control entries inside my SharePoint solution. Well after analysing that I came to the solution. So below are the steps described for that:

1. Open your SharePoint web part project inside visual studio 2010.

2. Select the web part folder for which you want to change the safe control entries in web.config file.

3. Press F4 to open properties window (I am not talking here for property page.).

4. In properties windows there is last entry of properties displaying as “Safe Control Entries

5. Click on the eclipse sign in front of “Safe Control Entries” value.

6. Inside “Safe Control Entries” pop up window, check for Namespace properties inside SafeControlEntry1 properties panel.

7. Change value of namespace property according to your namespace and class and click ok.

8. Save and build the solution and deploy it again.

9. Now after successful deployment check web.config of site and voilà you’ll find the correct safe type entries of your web part.

Happy Share Pointing J

Microsoft made the excellent integration of SharePoint with Visual Studio 2010. Good to see that.

In my next blogs I’ll come with these types of enhancements that visual studio provides for SharePoint 2010.


6 thoughts on “Add Safe Control Entries to SharePoint 2010 Web Parts using VS2010

  1. Oh my goodness! an incredible write-up dude. Thank you Even so My business is experiencing dilemma with ur rss . Don’t know why Unable to subscribe to it. Can there be anyone obtaining identical rss difficulty? Anybody who knows kindly respond. Thnkx

  2. Thank you, I changed the names in a Visual Webpart and encountered the “safe control” error. Fine write up.

  3. hey it didn’t worked and i wonder it worked for these guys here ,Yes ur making a safe entry in solution but what if it is not adding anything on web.config ?????

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s