Logo 
Search:

Sharepoint 2010 Articles

Submit Article
Home » Articles » Sharepoint 2010 » Design and CustomizationRSS Feeds

Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010

Posted By: Sekaran Mylsamy     Category: Sharepoint 2010     Views: 5005

Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010

 

Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010

 

 

Although I originally saw the new Visual Studio Tools for SharePoint 2010 back in August 2009, this past week was the first opportunity that I was able to get down to business with them, working with a web part solution (I don’t get to develop as much as I’d like to these days…). The beauty of these tools is that they not only (finally) give you a true “F5” approach to developing SharePoint applications, but they also build out and deploy web part solutions automatically for you. Indeed, every run of your application goes through the packaging and deployment process.

 

Before I get into this, I want to say that to a jaded old SharePoint developer, these tools are like manna from heaven. Not only is ease of use greatly improved, but so is speed of deployment and debugging.

 

However, unless you want your feature to be named “Feature1” and your solution to be named “MySolution”, and you want your assembly to be named exactly the same as your project, you’ll want to brand your solution a bit. Renaming a project and/or a component Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010 | The White Pages Page 2 of 12 Page 2 of 12

 

file will do a certain amount of refactoring automatically for you, but it isn’t complete and there are a few gotchas. I thought that I’d outline a few of them,and walk you through a branding process. This example uses a Visual Basic project,and there will be differences with C#, but the concepts remain the same.

 

1. Create your Visual Web Part, and give it a name. In this case, the name will be “Hello World” (Original, huh?)

 

2. Next, change the Web part names from “VisualWebPart1” to your name, in this case “HelloWorld” (notice the lack of spaces). When asked to perform a rename of all references, select yes. Don’t get too excited, it only changes code references.

 

3. Then, do a search and replace (Ctl-H) on the entire solution, and replace “VisualWebPart1” with your name – in our case “HelloWorld”. Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010 | The White Pages Page 5 of 12 Page 5 of 12

 

It should find and replace 5 references (for a VB.NET project at least).

 

4. If you want to change the name of your assembly and/or root namespace, go to project properties and do so. In our case, the Assembly name will be changed from “Hello World” to “SecondFoundation.HelloWorld”, and the root namespace will be changed from “Hello_World” to “SecondFoundation.HelloWorld”.

 

5. Next, edit the SharePointProjectItem.spdata file. This is a hidden file and you’ll need to turn on the “Show All Files” option in the solution explorer. This file controls the auto generation of several project components.

 

In the SafeControl entry, you’ll find that the Namespace attribute reflects the original name of the assembly. You’ll need to update it to reflect your change:

 

6. Next, edit your xxxx.webpart file (in our case HelloWorld.webpart). You’ll need to change the name attribute of the type entry in the <metaData> section to reflect your changes.

While you’re at it, you should likely change the Title and Description properties to something meaningful, although this isn’t required.

 


 

7. You’ll need to edit your xxxxxxUserControl.ascx file (in our Case

HelloWorldUserControl.ascx) and change the Inherits attribute from the Control entry (the last line) to reflect the namespace changes.

 

8. Optionally, edit the Elements.xml file, and change the Group property to something meaningful.

 

9. Open up the Features section in the Solution Explorer, and change the name from Feature1 to something meaningful. In our case, to continue on with my highly creative theme, we’ll call it HelloWorld.

 

10. Finally, Edit your .ascx file and add some content to allow us to see the web part on the page. I’ll leave it to you to guess what content I’m adding….. Run your project, and add your new web part to the page that pops up. All should be well.

Share: 



Sekaran Mylsamy
Sekaran Mylsamy author of Configuring and Branding a Visual Web Part Solution for SharePoint 2010 With Visual Studio 2010 is from Bangalore, India. Sekaran Mylsamy says I have totally 10 + years experience in Microsoft Technologies (.NET and SharePoint).
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!