<?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] : SPC09, Feature</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SPC09/Feature/default.aspx</link><description>Tags: SPC09, Feature</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>Writing to the Property Bag using CAML in SP2010</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/writing-to-the-property-bag-using-caml-in-sp2010.aspx</link><pubDate>Tue, 20 Oct 2009 15:51:32 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:1005</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=1005</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/writing-to-the-property-bag-using-caml-in-sp2010.aspx#comments</comments><description>&lt;p&gt;There are a number of feature improvements in SharePoint 2010.&amp;#160; They have made many changes which allow you to do more with features when they are activated or upgraded.&amp;#160; One of the new features it the ability to write to the property bag.&amp;#160; To do this we just make use of the new &lt;em&gt;PropertyBag &lt;/em&gt;element in your elements.xml file.&amp;#160; Here is what a file might look like that writes to the property bag.&amp;#160; As usual, I’ll point out that features or syntax could change.&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;&amp;lt;&lt;span style="color:#cc7832;"&gt;Elements&lt;/span&gt; &lt;span style="color:silver;"&gt;xmnlns&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;http://schemas.microsoft.com/sharepoint/&lt;/span&gt;&amp;quot;&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160; &amp;lt;&lt;span style="color:#cc7832;"&gt;PropertyBag&lt;/span&gt; &lt;span style="color:silver;"&gt;ParentType&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;Web&lt;/span&gt;&amp;quot;&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;span style="color:#cc7832;"&gt;Property&lt;/span&gt; &lt;span style="color:silver;"&gt;Name&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;MyCustomProperty1&lt;/span&gt;&amp;quot; &lt;span style="color:silver;"&gt;Value&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;some value&lt;/span&gt;&amp;quot; /&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;span style="color:#cc7832;"&gt;Property&lt;/span&gt; &lt;span style="color:silver;"&gt;Name&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;MyCustomProperty2&lt;/span&gt;&amp;quot; &lt;span style="color:silver;"&gt;Value&lt;/span&gt;=&amp;quot;&lt;span style="color:#a5c25c;"&gt;4&lt;/span&gt;&amp;quot; /&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160; &amp;lt;/&lt;span style="color:#cc7832;"&gt;PropertyBag&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;lt;/&lt;span style="color:#cc7832;"&gt;Elements&lt;/span&gt;&amp;gt;&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;I will point out that whatever type you initialize the property with, it will become semi-permanent.&amp;#160; Currently, this applies for integers and date/time.&amp;#160; If you try to save another type in an existing property later, you will end up with a null value being stored. This will save me some time in the future as I have had to write code to do this in the past.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=1005" 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/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></channel></rss>