<?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] : Code Access Security</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Code+Access+Security/default.aspx</link><description>Tags: Code Access Security</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>New level of trust in SharePoint 2013 Preview</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/08/12/new-level-of-trust-in-sharepoint-2013-preview.aspx</link><pubDate>Mon, 13 Aug 2012 02:37:27 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:5843</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=5843</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2012/08/12/new-level-of-trust-in-sharepoint-2013-preview.aspx#comments</comments><description>&lt;p&gt;When it comes to development, the introduction of the application model overshadows many of the other new things happening in SharePoint 2013 development.&amp;#160; I noticed one particular change as I was working on a new slide deck regarding the change to the default trust level of a web application.&amp;#160; In SharePoint 2007 and SharePoint 2010, the &lt;em&gt;Trust&lt;/em&gt; element was set to a value of &lt;em&gt;WSS_Minimal&lt;/em&gt;.&amp;#160; Effectively what this did was it meant that any DLL deployed to the web application bin folder was untrusted.&amp;#160; This meant your code had to either run in the GAC (giving it full trust) or you had to specify Code Access Security (CAS) policies to enable partial trust.&amp;#160; CAS policies were quite complicated and most SharePoint developers did not know how to implement them.&amp;#160; However, in the 2007 days I was a big fan of them and got many developers started with this &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;blog post&lt;/a&gt; and later with this post for &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/20/deploying-a-web-part-with-code-access-security-in-visual-studio-2010-sp2010.aspx"&gt;SharePoint 2010&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In SharePoint 2013 Preview, this changes.&amp;#160; The trust level is now set to Full.&amp;#160; &lt;/p&gt;  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;providers&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;siteMap&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;trust&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;level&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Full&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;originUrl&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;legacyCasModel&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;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;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;transformers&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;According to the very little information I have found on the topic this is due to the fact that .NET 4.0 has a new CAS model.&amp;#160; The &lt;em&gt;legacyCasModel&lt;/em&gt; attribute is set to true to enable previously written code with CAS policies to still function.&amp;#160; What this means is that code can now be deployed to the bin folder (which is faster) and it will have the same permissions as if deployed to the GAC.&amp;#160; Now what this means from a security stand point is up for debate I am sure.&amp;#160; However when Visual Studio 2010 came out everyone started deploying to the GAC any ways since it was just so much easier.&amp;#160; In reality, it probably doesn’t affect things much in the scheme of things.&amp;#160; Of course if you are developing sandboxed solutions or for the new app model this makes little difference to you.&amp;#160; I still thought it was an interesting change.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=5843" width="1" height="1"&gt;</description><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/Visual+Studio+11/default.aspx">Visual Studio 11</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2013/default.aspx">SharePoint 2013</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2013+Preview/default.aspx">SharePoint 2013 Preview</category></item><item><title>Slides and Code Samples from SharePoint Saturday Kansas City</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/12/16/slides-and-code-samples-from-sharepoint-saturday-kansas-city.aspx</link><pubDate>Wed, 16 Dec 2009 15:58:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:1178</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=1178</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/12/16/slides-and-code-samples-from-sharepoint-saturday-kansas-city.aspx#comments</comments><description>&lt;p&gt;I had a great time at SharePoint Saturday Kansas City.&amp;#160; &lt;a href="http://twitter.com/mosslover"&gt;@MossLover&lt;/a&gt; and &lt;a href="http://twitter.com/sharepointkevin"&gt;@SharePointKevin&lt;/a&gt; as well as many others did a great job organizing this event.&amp;#160; I met a bunch of great new people and I got to see some familiar faces again.&amp;#160; I had the privilege of speaking about Code Access Security again using Visual Studio 2010 and SharePoint 2010.&amp;#160; As promised, I am posting my slides and code samples from the talk.&amp;#160; You can find them at the bottom of this post.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=1178" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/dotnettipoftheday/attachment/1178.ashx" length="1075392" type="application/vnd.openxmlformats-officedocument.pres" /><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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Presentations/default.aspx">Presentations</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/SP2010+Beta/default.aspx">SP2010 Beta</category></item><item><title>Deploying a Web Part with Code Access Security in Visual Studio 2010 (SP2010)</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/20/deploying-a-web-part-with-code-access-security-in-visual-studio-2010-sp2010.aspx</link><pubDate>Fri, 20 Nov 2009 20:38:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:1109</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>20</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=1109</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/20/deploying-a-web-part-with-code-access-security-in-visual-studio-2010-sp2010.aspx#comments</comments><description>&lt;p&gt;By now, you have heard about how the SharePoint 2010 development experience has been improved.&amp;#160; We can easily deploy web parts and other code without having to manually manipulate any XML files.&amp;#160; What about under partial trust though?&amp;#160; Many of you that know me know that I have pushed using Code Access Security quite a bit through a series of blog &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;posts&lt;/a&gt; and &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/08/slides-and-code-samples-from-tulsa-techfest.aspx"&gt;talks&lt;/a&gt;.&amp;#160; So it would be irresponsible of me not to talk about how we can do that in Visual Studio 2010.&amp;#160; The good news is that it is a lot easier.&lt;/p&gt;  &lt;p&gt;Let’s start by creating a new SharePoint project in Visual Studio 2010 and creating a new Web Part project item.&amp;#160; In this case we are talking about deploying a Farm Solution, not a Sandboxed Solution.&amp;#160; Note: we are going to talk about a traditional web part today, and not a Visual Web Part.&amp;#160; Visual Web Parts are simply not supposed under partial trust.&amp;#160; More on that later below.&amp;#160; My web part has some simple code which uses ASP.NET and also hits the SharePoint object model to display the title of the site in a label.&amp;#160; Here is what the code looks like.&lt;/p&gt;  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;&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;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; 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;&amp;lt;div&amp;gt;My Cool Web Part!&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;});&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; 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:blue;"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515;"&gt;&amp;quot;Site Title: {0}&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;SPContext&lt;/span&gt;.Current.Web.Title) });&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; &lt;span style="color:blue;"&gt;base&lt;/span&gt;.CreateChildControls();&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;When you create a new project, it deploys to the GAC by default.&amp;#160; We start by changing this on the project properties.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASWebApplication_27C5F577.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CASWebApplication" border="0" alt="CASWebApplication" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASWebApplication_thumb_0DF1BF48.png" width="306" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This effectively changes the &lt;em&gt;DeploymentTarget &lt;/em&gt;attribute on Assembly element in the Manifest.xml.&amp;#160; At this point, you may be asking.&amp;#160; “Sweet, is that it?&amp;#160; Does it take care of the CAS policy for me?”&amp;#160; The answer to that of course is “No.”&amp;#160; However, it is quite easy to add it.&amp;#160; Let’s see what happens if we try to deploy it as is.&amp;#160; I’ll just hit F5 to start debugging.&amp;#160; I then add my web part to any existing page, and I immediately get hit with the following in Visual Studio.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASSecurityExceptionYellowScreen_3B72DF0B.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CASSecurityExceptionYellowScreen" border="0" alt="CASSecurityExceptionYellowScreen" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASSecurityExceptionYellowScreen_thumb_5F2C06A5.png" width="600" height="153" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;em&gt;System.Security.SecurityException: Request for the permission of type &amp;#39;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&amp;#39; failed.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Luckily we know how to fix this.&amp;#160; Hopefully, this will also help new developers when they get this error in the future and aren’t sure what to do.&amp;#160; We need to grant permissions to this assembly to use the object model as well as a few other things.&amp;#160; We’ll start by using a standard set of IPermission elements that I have used in past &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;posts&lt;/a&gt;.&amp;#160; This gives me basic ASP.NET, SharePoint object model, and Security permissions.&lt;/p&gt;  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CodeAccessSecurity&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;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PolicyItem&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;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PermissionSet&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;NamedPermissionSet&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &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;Permission set for VisualWebPartProject1.&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;AspNetHostingPermission&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Level&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Minimal&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;SecurityPermission&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Flags&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Execution,ControlPrincipal,ControlAppDomain,ControlDomainPolicy,ControlEvidence,ControlThread&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;ObjectModel&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;#160; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Read&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;UserName&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Read&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Write&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Append&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;PathDiscovery&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&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;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PermissionSet&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;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assemblies&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assembly&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;VisualWebPartProject1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;#160; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assemblies&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;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PolicyItem&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;CodeAccessSecurity&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;You can use this in your code almost exactly but two small changes are required.&amp;#160; First, you need to change your assembly name to whatever you have called yours.&amp;#160; Secondly, if you look at that SharePointPermission, you’ll notice it says version 12.0.0.0.&amp;#160; We need to change this to 14.0.0.0 since we are working with SharePoint 2010 now.&amp;#160; Adding this to your package is quite easy.&amp;#160; In the Solution Explorer, locate Package and then Package.package and open it.&amp;#160; This will bring open the package designer.&amp;#160; Click on the &lt;em&gt;Manifest&lt;/em&gt; tab at the bottom and then expand &lt;em&gt;Edit Options&lt;/em&gt;.&amp;#160; The way this works is that you can paste any &lt;em&gt;additional&lt;/em&gt; elements here and it will merge your items with the ones it automatically generates.&amp;#160; Here is what I would paste in.&lt;/p&gt;  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#a31515;"&gt;xml&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;encoding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;utf-8&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;Solution&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;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CodeAccessSecurity&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;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PolicyItem&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PermissionSet&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;NamedPermissionSet&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &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;Permission set for VisualWebPartProject1.&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;AspNetHostingPermission&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Level&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Minimal&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;SecurityPermission&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Flags&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Execution,ControlPrincipal,ControlAppDomain,ControlDomainPolicy,ControlEvidence,ControlThread&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;/span&gt;&amp;quot;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;ObjectModel&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;#160; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Read&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;UserName&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;IPermission&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Read&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES\VisualWebPartProject1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Write&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Append&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;PathDiscovery&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;$AppDir$&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PermissionSet&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assemblies&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;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assembly&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;VisualWebPartProject1&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;#160; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Assemblies&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;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PolicyItem&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;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CodeAccessSecurity&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;Solution&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;Here is what it would look like on the screen.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASPackageEditor_2CC83326.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CASPackageEditor" border="0" alt="CASPackageEditor" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASPackageEditor_thumb_5DE76DC6.png" width="606" height="526" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If everything is correct, you will see the merged result up top.&amp;#160; If there is an error in your XML, you will also see it there.&amp;#160; Now let’s deploy the solution and see if we can add the web part to an existing page.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASAPTCAError_0AFC5A95.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CASAPTCAError" border="0" alt="CASAPTCAError" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASAPTCAError_thumb_4AC6411A.png" width="325" height="131" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Unfortunately, this is the error we get and it actually gives us good information.&amp;#160; We simply forgot to add the APTCA attribute (or AllowPartiallyTrustedCallers).&amp;#160; Just open your AssmeblyInfo.cs file and add the following line.&lt;/p&gt;  &lt;div style="font-family:consolas;background:white;color:black;font-size:10pt;"&gt;   &lt;p style="margin:0px;"&gt;[&lt;span style="color:blue;"&gt;assembly&lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;AllowPartiallyTrustedCallers&lt;/span&gt;()]&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;Redeploy your solution and try to add your web part again.&amp;#160; If all goes well, you will have a lovely web part on the screen that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASWorkingWebPart_3C87C82A.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CASWorkingWebPart" border="0" alt="CASWorkingWebPart" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/CASWorkingWebPart_thumb_38114763.png" width="491" height="238" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With the above set of CAS policies, you can probably get most of the code you want to do to work.&amp;#160; I mentioned Visual Web Parts above.&amp;#160; Here is the issue I am currently seeing.&amp;#160; If you remember my post on 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 will know that this is just a web part with a Page.LoadControl() method calling a User Control (.ascx).&amp;#160; Page.LoadControl requires a ton of permissions and I haven’t been able to figure them out.&amp;#160; This means, it simply will not work.&amp;#160; I posted something to the &lt;a href="http://social.msdn.microsoft.com:80/Forums/en-US/sharepoint2010programming/thread/f244f7f6-b0f6-4e0d-9f5f-c7d423cdda60"&gt;forums&lt;/a&gt; about it.&amp;#160; Paul Andrew was nice enough to respond to my post and state that Page.LoadControl simply will not function under partial trust.&amp;#160; It has a check in it to verify that it is not running under partial trust.&amp;#160; He also goes on to explain this is why you can’t use Visual Web Parts in sandboxed solutions.&lt;/p&gt;  &lt;p&gt;This may seem like a lot of steps, but really I just posted a lot of pictures.&amp;#160; Trust me it’s a lot fewer steps than it was before in MOSS 2007.&amp;#160; Just look at my old &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;post&lt;/a&gt; if you don’t believe me.&amp;#160; Now, you might ask why would I do this instead of a Sandboxed solution?&amp;#160; Sandboxed solutions are severely limited on what they can do with the SharePoint object model.&amp;#160; By default, the CAS policy that defines them can’t even connect to a database.&amp;#160; I can specify at a per assembly level here what each one can do.&amp;#160; That is a big advantage.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=1109" 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/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/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/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>Slides and Code Samples from Tulsa TechFest</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/08/slides-and-code-samples-from-tulsa-techfest.aspx</link><pubDate>Wed, 08 Oct 2008 15:15:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:732</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=732</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/08/slides-and-code-samples-from-tulsa-techfest.aspx#comments</comments><description>&lt;p&gt;Today, at TechFest, I gave my talk on Implementing Partial Trust in SharePoint and I had a great time.&amp;nbsp; As promised, here are the slides and code samples.&amp;nbsp; If you have any more questions, feel free to leave me a comment.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=732" width="1" height="1"&gt;</description><enclosure url="http://www.dotnetmafia.com/blogs/dotnettipoftheday/attachment/732.ashx" length="206331" 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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/TechFest/default.aspx">TechFest</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Presentations/default.aspx">Presentations</category></item><item><title>Error: System.Security.SecurityException: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/08/error-system-security-securityexception-request-for-the-permission-of-type-microsoft-sharepoint-security-sharepointpermission-microsoft-sharepoint-security-version-12-0-0-0-culture-neutral-publickeytoken-71e9bce111e9429c-fail.aspx</link><pubDate>Wed, 08 Oct 2008 14:22:41 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:731</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=731</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/08/error-system-security-securityexception-request-for-the-permission-of-type-microsoft-sharepoint-security-sharepointpermission-microsoft-sharepoint-security-version-12-0-0-0-culture-neutral-publickeytoken-71e9bce111e9429c-fail.aspx#comments</comments><description>&lt;p&gt;Since I am talking about &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/02/speaking-at-tulsa-tech-fest-again.aspx"&gt;Implementing Partial Trust using Code Access Security&lt;/a&gt; this week, I thought I would talk about the following error when using a web part that doesn&amp;#39;t have code access security set on it.&lt;/p&gt; &lt;p&gt;&lt;em&gt;System.Security.SecurityException: Request for the permission of type &amp;#39;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&amp;#39; failed.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;This is the first error that someone taking their first dive into using partial trust with SharePoint might receive.&amp;nbsp; The reason I post this today is that a lot of times when someone runs into an issue with partial trust, someone will just say deploy your DLL to the GAC or change your trust level to full.&amp;nbsp; You don&amp;#39;t need to this if you build your solution package (.wsp) to properly set permission levels.&amp;nbsp; If you run into this issue, check out my updated 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;Configuring Code Access Security on a Web Part&lt;/a&gt;.&amp;nbsp; I wrote that post some time ago, but I have updated it as I have become more familiar with the process.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=731" 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/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><item><title>Using SharePoint with Enterprise Library 4.0 under Partial trust</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/01/using-sharepoint-with-enterprise-library-4-0-under-partial-trust.aspx</link><pubDate>Wed, 01 Oct 2008 15:52:55 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:716</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=716</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/01/using-sharepoint-with-enterprise-library-4-0-under-partial-trust.aspx#comments</comments><description>&lt;p&gt;Last year, I &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/09/05/how-to-get-enterprise-library-working-with-sharepoint.aspx"&gt;posted&lt;/a&gt; on how to use Enterprise Library 3.1 with SharePoint under partial trust.&amp;nbsp; It was incredibly difficult to get it to work with SharePoint when using partial trust because none of the DLLs had the AllowPartiallyTrustedCallers attribute on them.&amp;nbsp; This meant in order to get it to work, you had to add it to every AssemblyInfo.cs in the solution, sign it with your own strong name key, and then build and deploy it.&amp;nbsp; It was a lot of effort.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.codeplex.com/entlib"&gt;Enterprise Library 4.0&lt;/a&gt; has been out for a few months now, but I have yet to comment on it.&amp;nbsp;&amp;nbsp; I am pleased to report that with this new release, none of this overhead is required.&amp;nbsp; All of the DLLs, have the AllowPartiallyTrustedCallers attribute which means all you have to do is reference the DLLs and assign appropriate permissions.&amp;nbsp; I recommend putting Enterprise Library DLLs in a solution package which will make setting permissions easier.&amp;nbsp; Last year&amp;#39;s post should have most of the settings that you will need.&lt;/p&gt; &lt;p&gt;If you got turned off trying to implement Enterprise Library in the past with SharePoint, you might give it another try.&amp;nbsp; With the APTCA change, it should make it much easier to use entlib for logging, exception handling, data access, or whatever.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=716" 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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Enterprise+Library/default.aspx">Enterprise Library</category></item><item><title>More on Manfiest.xml</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/04/more-on-manfiest-xml.aspx</link><pubDate>Thu, 04 Sep 2008 15:19:32 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:678</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=678</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/04/more-on-manfiest-xml.aspx#comments</comments><description>&lt;p&gt;There are a ton of tools out there to create SharePoint solution packages (.wsp files) for you, but it is still a good idea to know what those tools are creating for you exactly.&amp;nbsp; Sometimes, things don&amp;#39;t always work right, and you may need to customize or tweak your manifest file.&amp;nbsp; If you are new to SharePoint development, the Manifest.xml file is used during the deployment of a .wsp solution package.&amp;nbsp; It tells SharePoint what files to copy, what features to install, where to put your binaries, adds &lt;em&gt;SafeControl&lt;/em&gt; entries, as well as set code access security.&amp;nbsp; The file seems pretty straight forward but there are a lot of ways to mess it up.&amp;nbsp; As I pointed out in the past, do not put any &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/avoid-comments-in-a-sharepoint-deployment-manifest.aspx"&gt;comments&lt;/a&gt; in this file.&amp;nbsp; It will cause all kinds of FAIL.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I&amp;#39;ll start by go over the key elements of this file and point out some things you need to know about each one.&amp;nbsp; If you create any of these main elements, note, that they will always require some kind of child element, otherwise the file won&amp;#39;t validate.&amp;nbsp; The first element we will talk about is &lt;em&gt;FeatureManifests&lt;/em&gt;.&amp;nbsp; This name as it sounds is used to deploy features.&amp;nbsp; Your solution will install features but not activate them for you.&amp;nbsp; You can list multiple features to install here using the &lt;em&gt;FeatureManifest &lt;/em&gt;element.&amp;nbsp; It&amp;#39;s &lt;em&gt;Location&lt;/em&gt; attribute specifies the path to the feature (inside the DDF file).&amp;nbsp; What that means is the path specified to your feature.xml file will match whatever you have listed as the destination in your DDF file.&amp;nbsp; We can talk about DDF files again another day if necessary.&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;FeatureManifests&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;FeatureManifest&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;MyFeature\feature.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;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;FeatureManifests&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;TemplateFiles&lt;/em&gt; element is used to copy out any additional files to the SharePoint server.&amp;nbsp; These could be .webpart files, user controls, other XML files, application pages, master pages, etc.&amp;nbsp; SharePoint will not copy any file that is not listed here (except for binaries and feature.xml and related files).&amp;nbsp; Again, you can specify multiple &lt;em&gt;TemplateFile&lt;/em&gt; child elements to copy multiple files.&amp;nbsp; Part of what makes this file tricky is the paths.&amp;nbsp; Some are relative, some require you to specify something inside the 12 hive.&amp;nbsp; It takes some getting used to.&amp;nbsp; In this case, if you are copying additional files into a feature folder for a web part, you would specify something like &lt;em&gt;FEATURES\MyFeature\mywebpart.webpart&lt;/em&gt;.&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;TemplateFiles&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;TemplateFile&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;FEATURES\MyFeature\MyWebpart.webpart&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;TemplateFiles&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;Assemblies&lt;/em&gt; element specifies which binaries will be deployed to SharePoint and where.&amp;nbsp; You can copy multiple assemblies out at a time with a feature by specifying more than one &lt;em&gt;Assembly&lt;/em&gt; element.&amp;nbsp; The &lt;em&gt;Assembly &lt;/em&gt;element has a Location attribute which typically just contains the DLL name (again dependent on where the DLL is copied in your DDF file).&amp;nbsp; It also contains a &lt;em&gt;DepoymentTarget &lt;/em&gt;attribute which specifies wether to copy it to the GAC (&lt;em&gt;GlobalAssemblyCache&lt;/em&gt;) or the bin folder (&lt;em&gt;WebApplication&lt;/em&gt;).&amp;nbsp; It also contains a SafeControls element with the same syntax of what is used in the web.config.&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;Assemblies&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;Assembly&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;DeploymentTarget&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;WebApplication&lt;/span&gt;&amp;quot;&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;MySolution.dll&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;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;nbsp;&amp;nbsp;&amp;nbsp;&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;MySolution, 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;MySolution.WebParts&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;nbsp;&amp;nbsp;&amp;nbsp; &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;Assembly&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;Assemblies&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;One thing to note here is that if you do not specify at least one assembly with a SafeControl element, SharePoint will decide that your solution does not contain a &lt;em&gt;Web Application Resource&lt;/em&gt; and therefore will not deploy it when you specify a URL with stsadm.&amp;nbsp; So, I typically include this line even if I don&amp;#39;t have any controls or web parts in my solution.&amp;nbsp; You will get an error like the one below.&lt;/p&gt; &lt;p&gt;&lt;em&gt;This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;The last element, I am will talk about is &lt;em&gt;CodeAccessSecurity&lt;/em&gt;.&amp;nbsp; This of course is the most complex one.&amp;nbsp; I have posted on this &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;topic&lt;/a&gt; in the past and don&amp;#39;t forget, I will be &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/02/speaking-at-tulsa-tech-fest-again.aspx"&gt;speaking&lt;/a&gt; about it next month.&amp;nbsp; The post I have on it covers it in more detail that I will cover today.&amp;nbsp; The one thing, I will remind you of is that it is ok to specify multiple assemblies.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I haven&amp;#39;t talked about the root element yet. It&amp;#39;s pretty simple.&amp;nbsp; Just remember the &lt;em&gt;SolutionId&lt;/em&gt; needs to be unique.&amp;nbsp; The &lt;em&gt;ResetWebServer&lt;/em&gt; attribute can be set to false if you don&amp;#39;t want it to reset IIS on deployment.&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;Solution&lt;/span&gt;&lt;span style="color:blue;"&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;SolutionId&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;{B3270C0DF-EACA-4320-9B2A-C293435C5DF1}&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&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;span style="color:red;"&gt;ResetWebServer&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;/div&gt; &lt;p&gt;Anyhow, hopefully this will help someone out the next time they are looking at a manfiest.xml file.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=678" 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/Code+Access+Security/default.aspx">Code Access Security</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>Speaking at Tulsa Tech Fest again</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/02/speaking-at-tulsa-tech-fest-again.aspx</link><pubDate>Tue, 02 Sep 2008 16:10:51 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:676</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=676</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/02/speaking-at-tulsa-tech-fest-again.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://techfests.com/Tulsa/2008/default.aspx"&gt;Tulsa Tech Fest&lt;/a&gt; was a lot of fun last year and I am excited to be speaking at it again this year.&amp;nbsp; This year, I will be giving a talk on &lt;a href="http://techfests.com/Tulsa/2008/Speakers/CoreyRoth/default.aspx"&gt;Implementing Partial Trust in SharePoint&lt;/a&gt;.&amp;nbsp; It should be a good talk in explaining how to create SharePoint solutions that can deploy Code Access Security settings.&lt;/p&gt; &lt;p&gt;It also looks like the DotNetMafia might be involved in putting together an unofficial &amp;quot;social event&amp;quot;.&amp;nbsp; More details on that to come.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=676" 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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Presentations/default.aspx">Presentations</category></item><item><title>ReflectionPermission Required for LINQ to SQL under Partial Trust</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/01/28/reflectionpermission-required-for-linq-to-sql-under-partial-trust.aspx</link><pubDate>Mon, 28 Jan 2008 19:45:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:460</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=460</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/01/28/reflectionpermission-required-for-linq-to-sql-under-partial-trust.aspx#comments</comments><description>So by now, I can assume everyone has been listening to me and you are using partial trust in all of your SharePoint environments right?&amp;nbsp; Ok, probably not, but for the two of you in the world that are, this post is for you.&amp;nbsp; If you decide to use LINQ to SQL in any of your development, I have discovered that &lt;strong&gt;ReflectionPermission&lt;/strong&gt; is needed by LINQ to SQL.&amp;nbsp; I don&amp;#39;t know the exact permissions it needs yet, but if you are in a bind to get it to work in your partial trust you can use a line like the following.&amp;nbsp; I try to avoid giving any permission unrestricted access, but until you find out what the underlying class actually needs, it is dificult.&amp;nbsp; To get you by, use a line like this.&lt;font color="#0000ff" size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; 
&lt;p&gt;&amp;lt;&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;IPermission&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;class&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;version&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;1&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;Unrestricted&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; /&amp;gt;&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;Also some more obvious permissions LINQ to SQL will need is &lt;strong&gt;SqlClientPermission&lt;/strong&gt; and probably &lt;strong&gt;ConfigurationPermission&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=460" 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/LINQ+to+SQL/default.aspx">LINQ to SQL</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Code+Access+Security/default.aspx">Code Access Security</category></item><item><title>The DataSourceID of 'TopNavigationMenu' must be the ID of a control of type IHierarchicalDataSource.  A control with ID 'topSiteMap' could not be found.</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/12/05/the-datasourceid-of-topnavigationmenu-must-be-the-id-of-a-control-of-type-ihierarchicaldatasource-a-control-with-id-topsitemap-could-not-be-found.aspx</link><pubDate>Wed, 05 Dec 2007 20:32:33 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:22</guid><dc:creator>C-Dog's .NET Tip of the Day</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=22</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/12/05/the-datasourceid-of-topnavigationmenu-must-be-the-id-of-a-control-of-type-ihierarchicaldatasource-a-control-with-id-topsitemap-could-not-be-found.aspx#comments</comments><description>Today&amp;#39;s topic is how to resolve the following error. The DataSourceID of &amp;#39;TopNavigationMenu&amp;#39; must be the ID of a control of type IHierarchicalDataSource. A control with ID &amp;#39;topSiteMap&amp;#39; could not be found. Go ahead, search Google for...(&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/12/05/the-datasourceid-of-topnavigationmenu-must-be-the-id-of-a-control-of-type-ihierarchicaldatasource-a-control-with-id-topsitemap-could-not-be-found.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=22" 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/Error/default.aspx">Error</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Code+Access+Security/default.aspx">Code Access Security</category></item><item><title>How to get Enterprise Library working with SharePoint</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/09/05/how-to-get-enterprise-library-working-with-sharepoint.aspx</link><pubDate>Wed, 05 Sep 2007 22:41:41 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:32</guid><dc:creator>C-Dog's .NET Tip of the Day</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=32</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/09/05/how-to-get-enterprise-library-working-with-sharepoint.aspx#comments</comments><description>Once again, the most seemingly simple task with SharePoint has proved to be incredibly difficult. Continuing with my commitment to post the most information possible about SharePoint oddities, here is today&amp;#39;s post. My goal today, I thought was simple...(&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/09/05/how-to-get-enterprise-library-working-with-sharepoint.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=32" 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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Enterprise+Library/default.aspx">Enterprise Library</category></item><item><title>More on Code Access Security</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/08/28/more-on-code-access-security.aspx</link><pubDate>Tue, 28 Aug 2007 20:47:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:35</guid><dc:creator>C-Dog's .NET Tip of the Day</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=35</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/08/28/more-on-code-access-security.aspx#comments</comments><description>I had promised an update to my Code Access Security post, so here it is. Hopefully, by now you have stopped being a cowboy and got your DLL out of the GAC and put the trust level back to minimal. If not, it is time. Here is some more info. Not just web...(&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/08/28/more-on-code-access-security.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=35" 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/Code+Access+Security/default.aspx">Code Access Security</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><item><title>Avoid Comments in a SharePoint Deployment Manifest</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/avoid-comments-in-a-sharepoint-deployment-manifest.aspx</link><pubDate>Thu, 05 Jul 2007 17:42:35 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:46</guid><dc:creator>C-Dog's .NET Tip of the Day</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=46</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/avoid-comments-in-a-sharepoint-deployment-manifest.aspx#comments</comments><description>In order to properly install a web part with Code Access Security, it is necessary to create a deployment solution. My next post will cover these and the proper way to specify code access security for a web part. In the meantime though, I wanted to post...(&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2007/07/05/avoid-comments-in-a-sharepoint-deployment-manifest.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=46" 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/Code+Access+Security/default.aspx">Code Access Security</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Deployment/default.aspx">Deployment</category></item></channel></rss>