<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.dotnetmafia.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Corey Roth [MVP] : Feature, WebPart</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/WebPart/default.aspx</link><description>Tags: Feature, WebPart</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Intro to SharePoint 2010 Development: How to Build and Deploy a Web Part</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx</link><pubDate>Mon, 15 Feb 2010 20:17:41 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:2748</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>36</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=2748</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx#comments</comments><description>&lt;p&gt;If you are already familiar with SharePoint 2010, you already know how easy it is to build and deploy a web part now.&amp;#160; However, this post is for those that don’t keep up with SharePoint as some of us do and may not realize how the development experience has improved so much.&amp;#160; My post &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/22/intro-to-sharepoint-development-how-to-build-and-deploy-a-web-part.aspx"&gt;How to Build and Deploy a Web Part&lt;/a&gt; is by far the most popular post on DotNetMafia.com.&amp;#160; I wanted to make today’s post just as a point to show you how much less work is involved in deploying a web part.&amp;#160; I am going to group this post into sections in a similar manner as I did the post for the WSS3 post.&lt;/p&gt;  &lt;h5&gt;&lt;/h5&gt;  &lt;h5&gt;Environment&lt;/h5&gt;  &lt;p&gt;There can be entire talks about what the best way to develop is now, but we’ll start with the simplest.&amp;#160; Although you can install SharePoint on Windows 7 and directly develop on it, most people are going to say stick with a virtual machine and run Windows Server 2008 R2.&amp;#160; It’s certainly simpler to get all of the prerequisites installed if you stick with Windows Server.&amp;#160; The benefits to developing directly on a machine with SharePoint on it are so great now that I would recommend against &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/03/05/how-to-remote-debugging-a-web-application.aspx"&gt;remote debugging&lt;/a&gt; (although you still can).&amp;#160; The SharePoint Root (or the 12 hive as you called it) is now the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/sharepoint-2010-12-hive-2-14-hive.aspx"&gt;14 hive&lt;/a&gt; and is located at the predictable path below.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14&lt;/em&gt;&lt;/p&gt;  &lt;h5&gt;Coding the Web Part&lt;/h5&gt;  &lt;p&gt;Here is where things start to change.&amp;#160; Instead of creating a class library and adding references to the SharePoint DLLs, we simply use one of the new included SharePoint project templates as you can see here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroEmptyProject_43970EE2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroEmptyProject" border="0" alt="WebPartIntroEmptyProject" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroEmptyProject_thumb_138CBD61.png" width="519" height="369" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Start by using the Empty SharePoint Project template.&amp;#160; Also make sure you have it set to .NET Framework 3.5 as SharePoint does not run under .NET Framework 4.0 (don’t get me started).&amp;#160; You’ll notice you have many different project templates to choose from.&amp;#160; Most of these can also be used once you create an empty project.&amp;#160; On the next dialogue, pick farm solution.&amp;#160; I’ll go into the difference between sandboxed and farm solutions, but more than likely you are going to use farm solutions every time.&amp;#160; You also need to specify the URL to your server.&amp;#160; You can change that if you want but the default value will probably work for you in this case.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionType_19D393EF.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionType" border="0" alt="WebPartIntroSolutionType" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionType_thumb_4B5F0184.png" width="387" height="307" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This gives us a solution that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer_06B26743.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionExplorer" border="0" alt="WebPartIntroSolutionExplorer" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer_thumb_2661410B.png" width="163" height="156" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we are ready to build our new web part.&amp;#160; If you bring up the add new item context menu, you will see a number of choices for the types of new SharePoint Project Items (SPIs) that you can create.&amp;#160; We’re going to choose Web Part in this case.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSPI_6A357562.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSPI" border="0" alt="WebPartIntroSPI" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSPI_thumb_28BAC309.png" width="532" height="378" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;What is the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/introducing-the-visual-web-part-in-sharepoint-2010.aspx"&gt;Visual Web Part&lt;/a&gt; you ask?&amp;#160; That’s just a user control which relates directly to my second most popular post on &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/11/18/introduction-to-sharepoint-development-deploy-a-user-control-in-sharepoint.aspx"&gt;How to Deploy a User Control&lt;/a&gt;.&amp;#160; Now we’re finally ready to add some code.&amp;#160; We’re just going to take our code from the WSS3 post and use it here.&lt;/p&gt;  &lt;div style="font-family:consolas;background:black;color:white;font-size:13pt;font-weight:bold;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.ComponentModel;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; Microsoft.SharePoint;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; Microsoft.SharePoint.WebControls;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;namespace&lt;/span&gt; SharePointProject1.TestWebPart&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; [ToolboxItemAttribute(&lt;span style="color:#cc7832;"&gt;false&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;public&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;class&lt;/span&gt; &lt;span style="color:#ffc66d;"&gt;TestWebPart&lt;/span&gt; : WebPart&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;public&lt;/span&gt; TestWebPart()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;protected&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;override&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; CreateChildControls()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;base&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.CreateChildControls();&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Controls.Add(&lt;span style="color:#cc7832;"&gt;new&lt;/span&gt; Label() { Text = &lt;span style="color:#a5c25c;"&gt;&amp;quot;My Test SharePoint 2010 Web Part (Hello World)!&amp;quot;&lt;/span&gt; });&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;protected&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;override&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; RenderContents(HtmlTextWriter writer)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;base&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.RenderContents(writer);&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;The only line of code I added here was the line to add the label and set its text.&amp;#160; Everything else came from the template.&lt;/p&gt;  &lt;h5&gt;Describing the Web Part&lt;/h5&gt;  &lt;p&gt;In my WSS3 post, this is where I talked about building a .webpart file.&amp;#160; Well, you don’t need to worry about that any more as Visual Studio creates it for you.&amp;#160; Here is what solution explorer looks like after you add your first web part.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer2_43F31C0A.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionExplorer2" border="0" alt="WebPartIntroSolutionExplorer2" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer2_thumb_7C9DC617.png" width="213" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see the .webpart file is already there as well as an elements.xml file for a feature to deploy the web part.&amp;#160; The WSS3 post went on to talk about all of the things you need to know about building a feature.&amp;#160; This is still good stuff to know, but its already taken care of for you.&amp;#160; If you want to edit the basic feature information, just open it up in solution explorer and you get a nice new interface that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroFeatureEditor_152D6368.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroFeatureEditor" border="0" alt="WebPartIntroFeatureEditor" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroFeatureEditor_thumb_14C13073.png" width="390" height="227" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’m not going to waste space showing you the insides of the files it creates for you.&amp;#160; Just know it creates them for you and it saves you a ton of time.&lt;/p&gt;  &lt;h5&gt;Deploying via Solution Package&lt;/h5&gt;  &lt;p&gt;In my WSS3 post, I explained how to create a cab.ddf and manifest.xml file.&amp;#160; Well guest what?&amp;#160; That is taken care of for you now as well.&amp;#160; The Package.package file in the solution explorer provides another nice editor which allows you to choose with files go into the package.&amp;#160; You don’t have to keep track of a thing any more, it just builds the package and takes care of it for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroPackageEditor_42425036.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroPackageEditor" border="0" alt="WebPartIntroPackageEditor" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroPackageEditor_thumb_2CE49ACE.png" width="391" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;At this point, Visual Studio has created the .webpart file, the feature, and the solution package.&amp;#160; However, we still need to deploy it and if we could debug it that would be even cooler right?&amp;#160; Take a look at our new options in the Build menu.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBuildMenu_4574381E.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroBuildMenu" border="0" alt="WebPartIntroBuildMenu" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBuildMenu_thumb_59F9879C.png" width="244" height="192" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;   &lt;p&gt;We can build and rebuild just like any other project, but notice the options for Deploy, Package, and Retract.&amp;#160; Those are all SharePoint functions.&amp;#160; In this case, I want to deploy my solution.&amp;#160; Choosing deploy, we see the following in the output window.&lt;/p&gt;    &lt;p&gt;------ Build started: Project: SharePointProject1, Configuration: Debug Any CPU ------     &lt;br /&gt;&amp;#160; SharePointProject1 -&amp;gt; C:\Code\SharePointProject1\bin\Debug\SharePointProject1.dll      &lt;br /&gt;&amp;#160; Successfully created package at: C:\Code\SharePointProject1\bin\Debug\SharePointProject1.wsp      &lt;br /&gt;------ Deploy started: Project: SharePointProject1, Configuration: Debug Any CPU ------      &lt;br /&gt;Active Deployment Configuration: Default      &lt;br /&gt;Run Pre-Deployment Command:      &lt;br /&gt;&amp;#160; Skipping deployment step because a pre-deployment command is not specified.      &lt;br /&gt;Recycle IIS Application Pool:      &lt;br /&gt;&amp;#160; Recycling IIS application pool &amp;#39;SharePoint - 80&amp;#39;...      &lt;br /&gt;Retract Solution:      &lt;br /&gt;&amp;#160; Skipping package retraction because no matching package on the server was found.      &lt;br /&gt;Add Solution:      &lt;br /&gt;&amp;#160; Adding solution &amp;#39;SharePointProject1.wsp&amp;#39;...      &lt;br /&gt;&amp;#160; Deploying solution &amp;#39;SharePointProject1.wsp&amp;#39;...      &lt;br /&gt;Activate Features:      &lt;br /&gt;&amp;#160; Activating feature &amp;#39;Feature1&amp;#39; ...      &lt;br /&gt;Run Post-Deployment Command:      &lt;br /&gt;&amp;#160; Skipping deployment step because a post-deployment command is not specified.      &lt;br /&gt;========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========      &lt;br /&gt;========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========      &lt;br /&gt;&lt;/p&gt;    &lt;p&gt;From inspecting the text of the log, you can see that Visual Studio compiled, created a package, reset my Application Pool, Added the Solution, Deployed the Solution, and activated the feature.&amp;#160; Let’s check SharePoint and see if it’s really there.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroGallery_728924EC.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroGallery" border="0" alt="WebPartIntroGallery" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroGallery_thumb_2B33CEFA.png" width="514" height="23" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Checking the web part gallery, we see our .webpart file.&amp;#160; Let’s add it to a page and see how it looks.&amp;#160; Edit any page and use add a web part and you will see the new interface for choosing a web part.&amp;#160; It puts it in the Custom group by default.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroAddWebPart_5FD42B35.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroAddWebPart" border="0" alt="WebPartIntroAddWebPart" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroAddWebPart_thumb_0A405C53.png" width="553" height="306" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;One you hit and add finish editing, we see the web part working correctly.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroWorking_30A23F9E.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroWorking" border="0" alt="WebPartIntroWorking" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroWorking_thumb_173A3C64.png" width="555" height="211" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;You have to admit this is quite a bit easier than deploying a web part in SharePoint 3.&amp;#160; What if you want to debug though?&amp;#160; No problem.&amp;#160; Just set a breakpoint and choose debug from the build menu like you would any other type of project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBreakPointHit_5DB72C6C.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroBreakPointHit" border="0" alt="WebPartIntroBreakPointHit" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBreakPointHit_thumb_48597704.png" width="563" height="76" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As I mentioned earlier, if you are familiar with SharePoint 2010, this is nothing new to you.&amp;#160; However, my point today is for those who shied away from SharePoint in the past because the development experience was far from optimal.&amp;#160; Try it for yourself and you will see how easy it is to get up and running with your code.&amp;#160; Even with pictures this post is half the size of the WSS3 post.&amp;#160; That’s because it really is just that easy.&amp;#160; I really think Visual Studio 2010 will open the way for a new round of SharePoint developers.&amp;#160; Try it out today.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=2748" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/default.aspx">Feature</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/WebPart/default.aspx">WebPart</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Solution/default.aspx">Solution</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2010/default.aspx">SharePoint 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SPC09/default.aspx">SPC09</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SP2010+Beta/default.aspx">SP2010 Beta</category></item><item><title>Intro to SharePoint Development: How to Build and Deploy a Web Part</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/22/intro-to-sharepoint-development-how-to-build-and-deploy-a-web-part.aspx</link><pubDate>Wed, 22 Oct 2008 12:50:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:751</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>31</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=751</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/22/intro-to-sharepoint-development-how-to-build-and-deploy-a-web-part.aspx#comments</comments><description>&lt;p&gt;UPDATE: &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx"&gt;Building Web Parts in SharePoint 2010&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve recently helped out a number of developers new to SharePoint and I found that I have been often asked the same types of questions.&amp;nbsp; Most of those involve getting started and deployment, so today, I am beginning my series on getting started with SharePoint.&amp;nbsp; Most new developers find starting out pretty overwhelming, but once you get used to it, it does all make sense.&amp;nbsp; Hopefully this post will help the community and keep new SharePoint developers from getting scared off.&amp;nbsp; There have been a lot of posts on this topic I admit.&amp;nbsp; Since there are so many ways to do things, I wanted to write this post as a reference to new developers so they can see how I usually do things.&amp;nbsp; What I find is that most developers have no trouble getting a web part built, but when it comes time to deploy it, they are lost.&amp;nbsp; There are multiple ways to do this and not all of them are necessarily the right way.&lt;/p&gt; &lt;h4&gt;Environment&lt;/h4&gt; &lt;p&gt;Let&amp;#39;s start by talking about your development environment.&amp;nbsp; In an ideal situation, you probably have your own virtual machine with Windows Server 2008 (or 2003), MOSS 2007, and Visual Studio 2008 installed.&amp;nbsp; However, maybe you don&amp;#39;t have your own dedicated machine and you are going to be developing on a Windows XP machine, but deploying to a remote SharePoint server.&amp;nbsp; This is fine, but you are going to have to do some things a little differently.&amp;nbsp; First, you won&amp;#39;t be able to install the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/06/04/wss-3-0-tools-visual-studio-extensions-1-2-running-under-windows-vista.aspx"&gt;Visual Studio Extensions for SharePoint&lt;/a&gt;.&amp;nbsp; You can live without this though because most people I have ran into say they don&amp;#39;t use them.&amp;nbsp; Secondly, when it comes to deployment (which we&amp;#39;ll talk about down below), you are going to have to copy your source files (either manually or via solution package) to the server.&amp;nbsp; You are also going to have to &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/03/05/how-to-remote-debugging-a-web-application.aspx"&gt;remote debug&lt;/a&gt; but fret not my post on it makes it easy.&lt;/p&gt; &lt;p&gt;If you are developing on a desktop, another thing you will need to do is copy the SharePoint assemblies to your computer.&amp;nbsp; We can easily get these from a deployed SharePoint server.&amp;nbsp; However, this is a great time to take an aside and talk about some of the SharePoint directory structure.&lt;/p&gt; &lt;p&gt;&lt;em&gt;C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12&lt;/em&gt;&lt;/p&gt; &lt;p&gt;All SharePoint developers have that file path permanently burned into their memory.&amp;nbsp; It is often referred to as the 12 hive.&amp;nbsp; A lot of things happen within this folder.&amp;nbsp; Subfolders here contain the SharePoint binaries, Master Pages, Application Pages, User Controls, Configuration Files, and Features.&amp;nbsp;&amp;nbsp; Although SharePoint will let you customize any file in here, in general you don&amp;#39;t want to make changes to any of these builtin files as it puts you in an unsupported scenario.&amp;nbsp; If you want to customize a master page or a style, it is typically best that you make a copy of what you want to customize and go from there.&amp;nbsp; Here is a quick list of some of the key folders and what they are used for.&lt;/p&gt; &lt;table cellspacing="0" cellpadding="2"&gt;  &lt;tr&gt; &lt;td&gt;&lt;strong&gt;Folder&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;CONFIG&lt;/td&gt; &lt;td&gt;Contains &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx"&gt;partial trust&lt;/a&gt; configuration files&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;ISAPI&lt;/td&gt; &lt;td&gt;Binaries and SharePoint Web Services&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;LOGS&lt;/td&gt; &lt;td&gt;Error Logs (look here first when you get a strange error)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\CONTROLTEMPLATES&lt;/td&gt; &lt;td&gt;User Controls&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\FEATURES&lt;/td&gt; &lt;td&gt;SharePoint Features (turns functionality on and off)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\IMAGES&lt;/td&gt; &lt;td&gt;MainImages Folder&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\LAYOUTS&lt;/td&gt; &lt;td&gt;Pages and Styles&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\SiteTemplates&lt;/td&gt; &lt;td&gt;Definitions avaiable for deploying new sites&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\THEMES&lt;/td&gt; &lt;td&gt;Used to create custom themes in SharePoint&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;TEMPLATE\XML&lt;/td&gt; &lt;td&gt;Contains XSDs for any XML used with SharePoint&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; &lt;p&gt;Enough on that tangent, back to the assemblies that we need to copy.&amp;nbsp; Go to the above path and then go into the ISAPI folder.&amp;nbsp; Copy all of the DLLs from this folder onto your desktop machine in the corresponding folder name.&amp;nbsp; If you don&amp;#39;t have that folder, create it.&amp;nbsp; You may also copy them to the Global Assembly Cache as well.&amp;nbsp; Once you are this point, you are ready to being building a web part.&lt;/p&gt; &lt;h4&gt;Coding the Web Part&lt;/h4&gt; &lt;p&gt;Start by creating a new class library project in Visual Studio.&amp;nbsp; There are packages and tools out there to automate some of these steps, but its best that you learn how to do it first by hand, so you know how to troubleshoot it should something go wrong.&amp;nbsp; Next, you will want to add (at a minimum) a reference to Microsoft.SharePoint.dll.&amp;nbsp; You can either grab it out of the GAC (will be listed under Windows SharePoint Services) or use the copy that you put in your ISAPI folder.&amp;nbsp; After you add it, make sure &lt;em&gt;Copy Local&lt;/em&gt; is set to false on your reference.&amp;nbsp; You will also want to add System.Web since more than likely your web part will use an ASP.NET control in it.&amp;nbsp; You are now ready to create your web part.&amp;nbsp; To do this, create a new class and add a using statement for &lt;em&gt;Microsoft.SharePoint&lt;/em&gt;.&amp;nbsp; In the past, you would derive your class from &lt;em&gt;Microsoft.SharePoint.WebPart&lt;/em&gt; (and you still can), but now the more accepted way of doing things is to derive from the new &lt;em&gt;System.Web.UI.WebParts.WebPart&lt;/em&gt; class.&amp;nbsp; The latter comes from ASP.NET 2.0 and can actually be deployed outside of SharePoint.&amp;nbsp; Here is what our class is going to look like.&lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;TestWebPart&lt;/span&gt; : System.Web.UI.WebControls.WebParts.&lt;span style="color:#2b91af;"&gt;WebPart&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;{&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:blue;"&gt;override&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; CreateChildControls()&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color:blue;"&gt;base&lt;/span&gt;.CreateChildControls();&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Controls.Add(&lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Label&lt;/span&gt;(){Text = &lt;span style="color:#a31515;"&gt;&amp;quot;My Test Web Part (Hello World)!&amp;quot;&lt;/span&gt;});&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt; &lt;p style="margin:0px;"&gt;}&lt;/p&gt;&lt;/div&gt; &lt;p&gt;The content of the class is simple.&amp;nbsp; We use the overridden &lt;em&gt;CreateChildControls&lt;/em&gt; method to add ASP.NET controls to the page to do the rendering.&amp;nbsp; I simply call Control.Add and add a Label control with the text above.&amp;nbsp; Compile it and this web part is good to go, but there is the small matter of deploying it.&amp;nbsp; Compiling it yield you a DLL that has be deployed to SharePoint somehow.&amp;nbsp; SharePoint also needs to know where the web part is and how to reference it.&amp;nbsp; This is where the .webpart file comes in.&lt;/p&gt; &lt;h4&gt;Describing the WebPart&lt;/h4&gt; &lt;p&gt;The .webpart file is an XML file that tells SharePoint what to call your DLL and what assembly it is located in.&amp;nbsp; The easiest way to get started creating this file is to copy another one in SharePoint.&amp;nbsp; You can find plenty of examples by going to your web part gallery (Site Root -&amp;gt; Site Settings -&amp;gt; Web Parts).&amp;nbsp; this file simply describes the class and assembly of your web part as well as some default properties (i.e.: it sets a title and description).&amp;nbsp; You can also add your own properties by specifying a series of attributes on a property in your class.&lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;webParts&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;webPart&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/WebPart/v3&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;metaData&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MyWebPart.TestWebPart, MyWebPart, Version=1.0.0.0, Culture=neutral&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;importErrorMessage&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Cannot import this Web Part.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;importErrorMessage&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;metaData&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;data&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;properties&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Title&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;My Web Part&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Description&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;A test web part.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;properties&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;data&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;webPart&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Note: There is also a &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/08/21/the-difference-between-dwp-and-webpart.aspx"&gt;.dwp&lt;/a&gt; file, which comes from version 2, that can describe your webpart as well.&amp;nbsp; It still works but it is consider deprecated.&lt;/p&gt; &lt;h4&gt;Ghetto Deploying&lt;/h4&gt; &lt;p&gt;So far, we have built a web part and created a .webpart file so now it is time to deploy it.&amp;nbsp; We&amp;#39;ll start by doing it the &lt;em&gt;wrong&lt;/em&gt; way.&amp;nbsp; The first thing to know is that you can&amp;#39;t just copy your DLL into the bin folder of your web application unless you change to full trust (not recommended) or specify &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx"&gt;Code Access Security&lt;/a&gt;.&amp;nbsp; Specifying CAS when first starting out will make even the most seasoned developers run for the hills.&amp;nbsp; So we are going to start by deploying to the GAC.&amp;nbsp; In almost all situations, I recommend against this, but for the sake of getting you started, it is ok.&amp;nbsp; You can then follow the Code Access Security post later on how to set up everything properly.&lt;/p&gt; &lt;p&gt;Start by copying your compiled DLL into the Global Assembly Cache of your SharePoint server.&amp;nbsp; Keep in mind anytime you update this DLL, you will need to either reset IIS or recycle the application pool (otherwise the old version stays in memory).&amp;nbsp; The next thing you need to do is upload the .webpart file to the web part gallery of your site collection (again Site Root -&amp;gt; Site Settings -&amp;gt; Web Parts).&amp;nbsp; At this point, SharePoint will be able to recognize your web part and it can be added to a page.&amp;nbsp; If you click on the name of the web part in the gallery (in this case MyWebPart.webpart), it will display a preview of what it will look like on a page.&amp;nbsp; If everything is working correctly, you will see your web part, otherwise you will get an error.&amp;nbsp; At this point, you will have the following error.&lt;/p&gt; &lt;p&gt;&lt;span class="Apple-style-span" style="word-spacing:0px;font:13px verdana;text-transform:none;text-indent:0px;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;-webkit-border-horizontal-spacing:0px;-webkit-border-vertical-spacing:0px;-webkit-text-decorations-in-effect:none;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0;"&gt;&lt;em&gt;A web part on this web part page cannot be displayed or imported because it is not registered on this site as safe.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;This is because there is one more step to do.&amp;nbsp; Every web part or user control in SharePoint must be registered as safe to execute in the web.config.&amp;nbsp; To do this, find the &lt;em&gt;SafeControls&lt;/em&gt; element near the top and add the following line (changing it with your fully qualified assembly path).&lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;SafeControls&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;SafeControl&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Assembly&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MyWebPart, Version=1.0.0.0, Culture=neutral&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Namespace&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MyWebPart&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;TypeName&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;*&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Safe&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;True&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;SafeControls&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;Now when you go back to the web part gallery, it should give you a preview of your web part.&amp;nbsp; If it doesn&amp;#39;t check your assembly paths and make sure the file is deployed.&amp;nbsp; If you still have issues, check out this post on &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/06/troubleshooting-cannot-import-web-part-error.aspx"&gt;troubleshooting a web part&lt;/a&gt;.&amp;nbsp; Assuming you were able to get the web part to preview, you can also go add it to a page by going to any page, clicking Edit Page and then Add Web Part.&amp;nbsp; Scroll through the list until you find your web part and select it.&amp;nbsp; You should then see your web part on the page.&lt;/p&gt; &lt;h4&gt;Features&lt;/h4&gt; &lt;p&gt;So we talked about deploying a web part the wrong way.&amp;nbsp; Ok, it&amp;#39;s not necessarily wrong, but it really adds a lot of extra work&amp;nbsp; This can be automated quite a bit by using features and solution packages.&amp;nbsp; Creating a feature, allows you to turn on and off customizations to SharePoint at the click of a button.&amp;nbsp; They can be used to deploy web parts, site definitions, workflows, document libraries, and plenty of other things.&amp;nbsp; In this case, we are building a feature to automate the deployment of our .webpart file.&amp;nbsp; You can also specify a class (Feature Receiver) that is executed when the feature is installed, activated, deactivated, or uninstalled.&amp;nbsp; A feature typically consists of two XML files.&amp;nbsp; The first file Feature.xml (must be named that), describes the feature and where its feature receiver is (if any).&amp;nbsp; &lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Feature&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/sharepoint/&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Id&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;{BDD425C3-CA50-4aee-9170-73954044D764}&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Scope&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Site&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Hidden&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;False&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Title&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;My Web Part&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:red;"&gt;Description&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;My Test Web Part&lt;/span&gt;&amp;quot;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ElementManifests&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ElementManifest&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Location&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Elements.xml&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ElementManifests&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Feature&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;The &lt;em&gt;Id&lt;/em&gt; element contains a GUID.&amp;nbsp; Every feature needs a different one.&amp;nbsp; The &lt;em&gt;Scope &lt;/em&gt;attribute specifies where to deploy the feature.&amp;nbsp; Possible values are &lt;em&gt;Site, Web, WebApplication, &lt;/em&gt;and &lt;em&gt;Farm&lt;/em&gt;.&amp;nbsp; I would go into the difference in scopes, because this post is already getting long enough.&amp;nbsp; You will most likely use Site or Web for most things you do (&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/08/21/sharepoint-to-api-translation-guide.aspx"&gt;note on terms in API&lt;/a&gt;).&amp;nbsp; The &lt;em&gt;ElementManifest &lt;/em&gt;element makes calls to additional XML files.&amp;nbsp; Typically the other file is called Elements.xml (although it can be called anything).&lt;/p&gt; &lt;p&gt;The Elements.xml file can be used to deploy files, create document libraries, and many other functions.&amp;nbsp; I won&amp;#39;t go into the whole detail of this file (it&amp;#39;s in the SDK), but basically we are specifying that the &lt;em&gt;MyWebPart.webpart&lt;/em&gt; file should be copied into the web part gallery.&amp;nbsp; I will tell you what a few things are though.&amp;nbsp; In this case the Module element says that we are going to deploy something into a list that is located at &lt;em&gt;_catalogs/wp &lt;/em&gt;(this is the URL of the web part gallery).&amp;nbsp; How did I figure this out?&amp;nbsp; I looked at another example.&amp;nbsp; The File element deploys our MyWebPart.webpart file into the web part gallery.&amp;nbsp; I wont go into why you set the Type to &lt;em&gt;GhostableInLibrary&lt;/em&gt; right now.&amp;nbsp; Just know this is the value you will pretty much always use.&lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Elements&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;http://schemas.microsoft.com/sharepoint/&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Module&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;WebPartPopulation&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;List&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;113&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Url&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;_catalogs/wp&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;RootWebOnly&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;TRUE&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;File&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Url&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MyWebPart.webpart&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;GhostableInLibrary&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Module&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Elements&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;When the feature is activated, it will put the file in the web part gallery.&amp;nbsp; However, it won&amp;#39;t &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/03/04/reminder-delete-web-parts-from-gallery-when-changing-version-numbers.aspx"&gt;remove the item&lt;/a&gt; from the web part gallery on deactivation.&amp;nbsp; It&amp;#39;s pretty easy to do with code and I still plan to write a post on it.&amp;nbsp; For now, if you want the .webpart file gone you will have to delete it manually.&amp;nbsp; During the development cycle though, the only time it really is necessary to remove a .webpart file is if you have changed the namespace, class name, or public key token.&amp;nbsp; Here is what an elements file typically looks like for deploying a web part.&lt;/p&gt; &lt;p&gt;So where do all these files go?&amp;nbsp; Let&amp;#39;s talk about where you put them in your Visual Studio project first.&amp;nbsp; Typically, what you will do is create a folder structure in your project that matches the 12 hive.&amp;nbsp; So in this case, we will create a TEMPLATE\FEATURES folder.&amp;nbsp; We will then create a folder for our web part.&amp;nbsp; I am just calling it MyWebPart for now.&amp;nbsp; Here is what your solution will look like.&amp;nbsp; This folder is where you will put Feature.xml, Elements.xml, and MyWebPart.webpart.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WindowsLiveWriter/BacktoBasicsHowtoBuildandDeployaWebPart_E55A/image_2.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="image" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WindowsLiveWriter/BacktoBasicsHowtoBuildandDeployaWebPart_E55A/image_thumb.png" width="238" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;To deploy the feature, copy it to the TEMPLATE\FEATURES folder in your 12 hive.&amp;nbsp; You then need to use stsadm command to install it.&amp;nbsp; The stsadm executable is located in the bin folder of the 12 hive.&amp;nbsp; You tend to use it a lot, so you might want to put it in your path environment variable.&amp;nbsp; Once you have located it, issue the following command.&lt;/p&gt; &lt;p&gt;&lt;em&gt;stsadm -o installfeature -name MyWebPart&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This makes the feature available to be activated.&amp;nbsp;&amp;nbsp; To activate it, go to Site Collection Features (Site Root -&amp;gt; Site Settings -&amp;gt; Site Collection Features).&amp;nbsp; Find the feature in the list and click the Activate button.&amp;nbsp; This deploys the web part to the gallery and it can be added to pages as before.&amp;nbsp; If you ever want to remove the feature, use the &lt;em&gt;uninstallfeature&lt;/em&gt; operation.&amp;nbsp; You will want to deactivate the feature first, otherwise you will have to use the -force parameter when using stsadm.&lt;/p&gt; &lt;h4&gt;Deploying Via Solution Package&lt;/h4&gt; &lt;p&gt;Features are nice, but we can take this one step further.&amp;nbsp; A solution package (.wsp file) allows you to package your entire solution into one .wsp file for deployment.&amp;nbsp; A .wsp file is simply a cab file with a manifest.xml file that tells SharePoint how to install the contents.&amp;nbsp; It will even deploy and install your feature for you, allowing you to skip the installation steps above.&amp;nbsp; Two files are required to build the .wsp file: cab.ddf and manifest.xml.&amp;nbsp; These files typically go into a folder called Solution in your Visual Studio project.&amp;nbsp; Cab.ddf tells the utility, makecab.exe, how to construct the .wsp file.&amp;nbsp;&amp;nbsp; Below is an example DDF file.&amp;nbsp; You will need to set the &lt;em&gt;CabinetNameTemplate&lt;/em&gt; to the filename you want for your wsp file.&amp;nbsp; You then specify a source and destination for each file you want copied.&amp;nbsp; In the example below, note that I am copying the DLL, Elements.xml, Feature.xml, and MyWebPart.webpart file.&amp;nbsp; &lt;/p&gt; &lt;div style="font-size:10pt;background:white;color:black;font-family:courier new;"&gt; &lt;p style="margin:0px;"&gt;; ** MyWebPart.wsp **&lt;/p&gt; &lt;p style="margin:0px;"&gt;.OPTION EXPLICIT&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Generate errors &lt;/p&gt; &lt;p style="margin:0px;"&gt;.Set CabinetNameTemplate=MyWebPart.wsp&lt;/p&gt; &lt;p style="margin:0px;"&gt;.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory&lt;/p&gt; &lt;p style="margin:0px;"&gt;.Set CompressionType=MSZIP;** All files are compressed in cabinet files&lt;/p&gt; &lt;p style="margin:0px;"&gt;.Set UniqueFiles=&amp;quot;ON&amp;quot;&lt;/p&gt; &lt;p style="margin:0px;"&gt;.Set Cabinet=on&lt;/p&gt; &lt;p style="margin:0px;"&gt;.Set DiskDirectory1=Package&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin:0px;"&gt;Solution\manifest.xml manifest.xml&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin:0px;"&gt;; binary&lt;/p&gt; &lt;p style="margin:0px;"&gt;bin\debug\MyWebPart.dll MyWebPart.dll&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin:0px;"&gt;; feature files&lt;/p&gt; &lt;p style="margin:0px;"&gt;TEMPLATE\FEATURES\MyWebPart\Elements.xml MyWebPart\Elements.xml&lt;/p&gt; &lt;p style="margin:0px;"&gt;TEMPLATE\FEATURES\MyWebPart\Feature.xml MyWebPart\Feature.xml&lt;/p&gt; &lt;p style="margin:0px;"&gt;&amp;nbsp;&lt;/p&gt; &lt;p style="margin:0px;"&gt;; web part files&lt;/p&gt; &lt;p style="margin:0px;"&gt;TEMPLATE\FEATURES\MyWebPart\MyWebPart.webpart FEATURES\MyWebPart\MyWebPart.webpart&lt;/p&gt;&lt;/div&gt; &lt;p&gt;I won&amp;#39;t go into manifest.xml again because I have already covered it once in this &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/04/more-on-manfiest-xml.aspx"&gt;post&lt;/a&gt;.&amp;nbsp; It&amp;#39;s this file that tells SharePoint how to deploy features, copy files, setup code access security, and add SafeControl entries to your web.config.&amp;nbsp; Once you create your solution files, build your project and then go to the command line.&amp;nbsp; The utility makecab.exe (should already be on your system) will actually create the wsp file.&amp;nbsp; In the command prompt, go to the root folder of your project and execute the following command.&amp;nbsp; It has to be executed from that folder because all of the paths are relative.&lt;/p&gt; &lt;p&gt;&lt;em&gt;makecab.exe /f solution\cab.ddf&lt;/em&gt;&lt;/p&gt; &lt;p&gt;You can automate this step when you build, by creating a &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/08/28/using-msbuild-to-create-a-sharepoint-wsp-file-on-build.aspx"&gt;build action&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;If you are working on a remote server, you will need to copy the .wsp file onto the server. Add and deploy the solution with the following commands.&lt;/p&gt;&lt;pre&gt;stsadm -o addsolution -filename package\MyAssembly.wsp
stsadm -o deploysolution -name MyAssembly.wsp -immediate -allContentUrls -allowGacDeployment
stsadm -o execadmsvcjobs&lt;/pre&gt;
&lt;p&gt;At this point if all goes well, your solution will be installed and deployed.&amp;nbsp; This eliminates all the steps of manually copying files into SharePoint.&amp;nbsp; You can then activate your feature like before (remember it installs the feature for you) and add your web part to a page.&amp;nbsp; If you make an update to your web part, deploying is easy, just use the &lt;em&gt;upgradesolution&lt;/em&gt; stsadm command and it will update all the files in your solution.&amp;nbsp; Should you decide, you don&amp;#39;t need the solution any more, use the &lt;em&gt;retractsolution&lt;/em&gt; command.&amp;nbsp; After you issue either of those commands, you will need to follow it up with a &lt;em&gt;execadmsvcjobs&lt;/em&gt; command as shown above.&lt;/p&gt;
&lt;p&gt;This may sound like a lot, but it really isn&amp;#39;t bad.&amp;nbsp; It makes deployment really easy (especially to other servers).&amp;nbsp; Once you have your solution deployed and you want to make an update, you can also just directly copy out the binary to your server.&amp;nbsp; Not really a best practice, but it does speed things up quite a bit, since stsadm commands take a few seconds to run.&lt;/p&gt;
&lt;p&gt;Once you get the hang of it and are familiar with the deployment process, you really need to consider deploying your solution to the bin folder by deploying your solution under partial trust.&amp;nbsp; Remember right now, you are deploying to the GAC which is not ideal.&amp;nbsp; My post on &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx"&gt;Code Access Security&lt;/a&gt; walks you through the whole process and provides more details on how solution packages are built.&lt;/p&gt;
&lt;h4&gt;User Controls&lt;/h4&gt;
&lt;p&gt;By now, you may be thinking, I went through all of that and I still have to render stuff to the screen using straight code?&amp;nbsp; I hear you.&amp;nbsp; It&amp;#39;s not any fun at all and can be a &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/08/04/to-web-part-or-not-to-web-part.aspx"&gt;controversy&lt;/a&gt; among some SharePoint developers.&amp;nbsp; You do have a couple of alternatives, use the &lt;a href="http://www.codeplex.com/smartpart"&gt;SmartPart&lt;/a&gt; or &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/07/30/how-to-build-your-own-smartpart-control.aspx"&gt;write your own&lt;/a&gt;.&amp;nbsp; I typically go with the latter.&amp;nbsp; This simple web part uses Page.LoadControl to load the .ascx file you specify. &lt;/p&gt;
&lt;p&gt;This is quickly becoming the longest post I have ever written.&amp;nbsp; I&amp;#39;ve attached the code I used in this post.&amp;nbsp; You can use it to verify that you put your own web part together correctly or you can use it as a starting point.&amp;nbsp; I hope this provides enough information for a new SharePoint developer to get started.&amp;nbsp; I certainly wish I had this much info condensed in one place when I was starting out.&amp;nbsp; You may also want to check out one of the many solution generating tools out there such as &lt;a href="http://www.codeplex.com/stsdev"&gt;stsdev&lt;/a&gt;.&amp;nbsp; Please leave a comment if this helps or if you have any questions.&amp;nbsp; If I am missing anything or you think I need to add anything, also please let me know.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=751" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/dotnettipoftheday/attachment/751.ashx" length="25753" type="application/x-zip-compressed" /><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/default.aspx">Feature</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/WebPart/default.aspx">WebPart</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Deployment/default.aspx">Deployment</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Solution/default.aspx">Solution</category></item><item><title>Troubleshooting: Cannot import Web Part Error</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/06/troubleshooting-cannot-import-web-part-error.aspx</link><pubDate>Mon, 06 Oct 2008 22:20:54 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:726</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>18</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=726</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/06/troubleshooting-cannot-import-web-part-error.aspx#comments</comments><description>&lt;p&gt;Let&amp;#39;s face it, any new SharePoint developer is going to run into an error such as the one below when starting out.&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="color:#1f497d;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;em&gt;[WebPartPageUserException: Cannot import MyWebPart Web Part.]&lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="color:#1f497d;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;em&gt;&amp;nbsp; at Microsoft.SharePoint.WebPartPages.WebPartImporter.CreateWebPart(Boolean clearConnections) &lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="color:#1f497d;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;em&gt;&amp;nbsp; at Microsoft.SharePoint.WebPartPages.WebPartImporter.Import(SPWebPartManager manager, XmlReader reader, Boolean clearConnections, Uri webPartPageUri, SPWeb spWeb) &lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin:0in 0in 0pt;"&gt;&lt;span style="color:#1f497d;"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;em&gt;&amp;nbsp; at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CompressWebPartNoSave(Boolean isClosed)&lt;/em&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;p&gt;I&amp;#39;ve found myself doing a LOT of troubleshooting of this for developers, so I decided it was time to post the steps in helping me resolve this issue.&amp;nbsp; This issue can be a number of things, but the first place I always check is the web part gallery.&amp;nbsp; If you can&amp;#39;t view your web part in the gallery, chances are it&amp;#39;s not going to work.&amp;nbsp; The first thing you need to do is verify that your web part is in fact in the list.&amp;nbsp; If it&amp;#39;s not, you need to go install it (either manually or via solution package / feature).&amp;nbsp; If it is there, click on the link to the web part (i.e. MyWebPart.webpart), not the icon.&amp;nbsp; If you get an error like the one above, you definitely know something is wrong with the way the web part is installed on your server.&lt;/p&gt; &lt;p&gt;The next thing you do is click the Edit icon (the one next to the webpart link).&amp;nbsp; From this page, you can make use of the View XML link to look at the .webpart file that is installed.&amp;nbsp; More than likely at this point, the assembly path is wrong to your DLL or the DLL is not installed on your system.&amp;nbsp; Confirm that the assembly path is correct given your DLL.&amp;nbsp; For example, if your DLL is strongly signed, make sure the public key token is listed on the assembly path.&amp;nbsp; If the DLL is not in the GAC, I recommend leaving off the PublicKeyToken becuase it will try and find that DLL in the global assembly cache which will give you an error saying that it cannot find the DLL.&amp;nbsp; Other issues I have ran into here is the version number.&amp;nbsp; Sometimes specify the version number as 1.0.* (for example).&amp;nbsp; This usually works but I have seen issues where it would not work unless you specified 1.0.0.0.&amp;nbsp; I am sure there is a reason for that, but I have no idea what it is.&amp;nbsp; Also remember, if you change your assembly path ever (i.e.: you change the PublicKeyToken or namespace) and redeploy, you need to delete the .webpart file out of the gallery.&amp;nbsp; You can do this manually or write code to do it with a feature receiver.&lt;/p&gt; &lt;p&gt;If you have verified that your .webpart is correct, make sure that the DLL for you web part actually exists.&amp;nbsp; I know this sounds obvious, but lots of things can cause a solution package to install silently which means your DLL may not be present in the bin folder or the GAC when you think it should be.&amp;nbsp; Also remember that you probably need to reset IIS (or at least the application pool), if you have deployed a DLL to the GAC for SharePoint to pick it up.&lt;/p&gt; &lt;p&gt;Of course, make sure you have a SafeControls entry in the web.config file for your assembly.&amp;nbsp; Although, this would probably result in a Cannot register this type as safe error.&amp;nbsp; This error can often times be quite frustrating because it will seem as if you have done all the steps to make sure it works and it just doesn&amp;#39;t.&amp;nbsp; Don&amp;#39;t forget to check the logs (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\logs) too.&amp;nbsp; This error will show up in there and there may be extra information in there to help you find your error.&amp;nbsp; Just keep at it and double check everything and usually you can find something.&lt;/p&gt;&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=726" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/default.aspx">Feature</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/WebPart/default.aspx">WebPart</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Deployment/default.aspx">Deployment</category></item><item><title>How to configure Code Access Security for a Web Part</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx</link><pubDate>Thu, 05 Jul 2007 23:00:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:45</guid><dc:creator>C-Dog's .NET Tip of the Day</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=45</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx#comments</comments><description>As a new SharePoint developer, you will be directed to install your first Hello World web part in the GAC. Right now red flags should be going off for any non-noob developer. This allows your code to operate with Full Trust (which is bad). To properly...(&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/how-to-configure-code-access-security-for-a-web-part.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=45" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/default.aspx">Feature</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/WebPart/default.aspx">WebPart</category></item></channel></rss>