<?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] : SharePoint 2010, WebPart, SP2010 Beta</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2010/WebPart/SP2010+Beta/default.aspx</link><description>Tags: SharePoint 2010, WebPart, SP2010 Beta</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Impress the Boss with the SharePoint 2010 Chart Web Part</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/24/impress-the-boss-with-the-sharepoint-2010-chart-web-part.aspx</link><pubDate>Wed, 24 Feb 2010 17:09:12 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:2811</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>56</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=2811</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/24/impress-the-boss-with-the-sharepoint-2010-chart-web-part.aspx#comments</comments><description>&lt;p&gt;Let’s face it.&amp;#160; Nowadays, management absolutely loves BI.&amp;#160; Especially when there are lots of pretty charts and graphs.&amp;#160; The thing is I’m not a BI guy.&amp;#160; Cubes scare me to death.&amp;#160; Luckily, there is the new snazzy Chart Web Part in SharePoint 2010 that gives you some BI like capabilities.&amp;#160; It doesn’t allow you to drill down and pivot and do all that fancy stuff, but it does let you make some nice graphs and charts that any ordinary developer can do.&lt;/p&gt;  &lt;p&gt;To get started, first you need an Enterprise version of SharePoint 2010.&amp;#160; Unfortunately, I used the key that was later determined to be the wrong one which led me to reinstall SharePoint with a new key.&amp;#160; If you don’t have any Enterprise options available, then you will be reinstalling.&amp;#160; Assuming, you do have an Enterprise key, you then need to activate the &lt;em&gt;SharePoint Server Enterprise Site Collection Features&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartFeature_3EA95F0B.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartFeature" border="0" alt="ChartWebPartFeature" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartFeature_thumb_5DEC05DE.png" width="563" height="43" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This adds the chart web part (among other things).&amp;#160; Then edit any page and add a Chart Web Part.&amp;#160; You can find it under Miscellaneous as of Beta 2 (they may have found it a new home in later versions).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartAdd_5D7FD2E9.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartAdd" border="0" alt="ChartWebPartAdd" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartAdd_thumb_2EBA1A47.png" width="429" height="216" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;When you add it to the page, it uses some dummy data and displays a simple bar chart.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDefault_272EAADA.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartDefault" border="0" alt="ChartWebPartDefault" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDefault_thumb_74CAD75A.png" width="282" height="270" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;At this point, you might be asking yourself “What kind of data can I bind this to?”.&amp;#160; By clicking &lt;em&gt;Data &amp;amp; Appearance, &lt;/em&gt;you will see the following screen which leads you to links to customize the appearance or bind to data.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDataAndAppearance_426703DB.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartDataAndAppearance" border="0" alt="ChartWebPartDataAndAppearance" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDataAndAppearance_thumb_1AC087B1.png" width="419" height="210" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We’ll start by going to &lt;em&gt;Connect Chat To Data&lt;/em&gt;.&amp;#160; Look at these great options we have to choose from.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDataSources_4C4BF546.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartDataSources" border="0" alt="ChartWebPartDataSources" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartDataSources_thumb_24A5791C.png" width="495" height="309" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We can connect to another web part, a list, an external content type (looks like they need to update the BDC wording they have there), and to Excel Services.&amp;#160; I tried going straight to an external content type, but I got a yellow screen.&amp;#160; Apparently that is broken on my version, but I’m sure it will work in RTM.&amp;#160; There is a work around though.&amp;#160; You can pick an external list using the &lt;em&gt;Connect to a List&lt;/em&gt; option.&amp;#160; This is exactly what I am going to do.&lt;/p&gt;  &lt;p&gt;Remember that external list I created on my &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/02/it-s-easy-to-configure-an-external-list-with-business-connectivity-services-bcs-in-sharepoint-foundation-2010.aspx"&gt;BCS&lt;/a&gt; blog post?&amp;#160; I’m going to use that list and extend it some.&amp;#160; What I did is I created a new custom list to contain Monthly Sales information.&amp;#160; I used an External Data field to allow the user to pick a product from the external content type and enter in some sales data in a field.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartList_320B8C22.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartList" border="0" alt="ChartWebPartList" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartList_thumb_7FA7B8A2.png" width="326" height="98" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is the list we are going to use on our chart.&amp;#160; On the next step of the wizard, we are allowed to pick a list.&amp;#160; Note that it also allows you to choose other sites in the collection as well.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartListDataSource_385262B0.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartListDataSource" border="0" alt="ChartWebPartListDataSource" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartListDataSource_thumb_430FBA05.png" width="359" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The next step allows you to filter your data first if you are so inclined.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWizardFilterData_57950983.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartWizardFilterData" border="0" alt="ChartWebPartWizardFilterData" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWizardFilterData_thumb_293B83D6.png" width="411" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The Chart Web Part has a ton of configurable options.&amp;#160; On this last step is where you will start seeing some of them.&amp;#160; The main thing to set here is your X and Y fields.&amp;#160; You can also specify something to group by as well.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWizardBindData_4F9D6721.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartWizardBindData" border="0" alt="ChartWebPartWizardBindData" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWizardBindData_thumb_4F31342C.png" width="463" height="295" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once you finish this last step, you’ll get something that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWithData_15AE2435.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartWithData" border="0" alt="ChartWebPartWithData" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartWithData_thumb_00506ECD.png" width="322" height="326" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So, what we have here is a chart bound to data coming from a database (via external content type) and a SharePoint list.&amp;#160; Pretty cool, right?&amp;#160; I think so.&amp;#160; It gets better though.&amp;#160; What if your boss doesn’t like bar charts?&amp;#160; No problem.&amp;#160; There are tons of chart types to choose from.&amp;#160; Just click on &lt;em&gt;Data &amp;amp; Appearance&lt;/em&gt; again and then &lt;em&gt;Customize Your Chart&lt;/em&gt;.&amp;#160; Look at all of these built in chart types you have.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsPie_2DD18E90.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartOptionsPie" border="0" alt="ChartWebPartOptionsPie" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsPie_thumb_7B01881B.png" width="391" height="225" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsBar_737618AE.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartOptionsBar" border="0" alt="ChartWebPartOptionsBar" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsBar_thumb_12B8BF82.png" width="385" height="193" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;On the next step, you can further customize the chart you choose.&amp;#160; It has some nice pre-built color themes and you can customize the size and what not.&amp;#160; It also gives you a live preview as you change settings.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsPie2_5D3FFD5C.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartOptionsPie2" border="0" alt="ChartWebPartOptionsPie2" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartOptionsPie2_thumb_7C82A42F.png" width="427" height="204" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Here is what my new chart looks like.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartPie_22E4877B.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="ChartWebPartPie" border="0" alt="ChartWebPartPie" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/ChartWebPartPie_thumb_22785486.png" width="244" height="218" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You can customize things even more by going to Advanced Properties.&amp;#160; It would probably take me a week to show you everything that this web part does, so I recommend you go try it out for yourself.&amp;#160; The charts and graphs this thing produces are so cool, you should have no issue getting your boss to sign off on the Enterprise license. :)&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=2811" 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/WebPart/default.aspx">WebPart</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Business+Connectivity+Services/default.aspx">Business Connectivity Services</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 2010 Development: How to Build and Deploy a Web Part</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx</link><pubDate>Mon, 15 Feb 2010 20:17:41 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:2748</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>36</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=2748</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/02/15/intro-to-sharepoint-2010-development-how-to-build-and-deploy-a-web-part.aspx#comments</comments><description>&lt;p&gt;If you are already familiar with SharePoint 2010, you already know how easy it is to build and deploy a web part now.&amp;#160; However, this post is for those that don’t keep up with SharePoint as some of us do and may not realize how the development experience has improved so much.&amp;#160; My post &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/10/22/intro-to-sharepoint-development-how-to-build-and-deploy-a-web-part.aspx"&gt;How to Build and Deploy a Web Part&lt;/a&gt; is by far the most popular post on DotNetMafia.com.&amp;#160; I wanted to make today’s post just as a point to show you how much less work is involved in deploying a web part.&amp;#160; I am going to group this post into sections in a similar manner as I did the post for the WSS3 post.&lt;/p&gt;  &lt;h5&gt;&lt;/h5&gt;  &lt;h5&gt;Environment&lt;/h5&gt;  &lt;p&gt;There can be entire talks about what the best way to develop is now, but we’ll start with the simplest.&amp;#160; Although you can install SharePoint on Windows 7 and directly develop on it, most people are going to say stick with a virtual machine and run Windows Server 2008 R2.&amp;#160; It’s certainly simpler to get all of the prerequisites installed if you stick with Windows Server.&amp;#160; The benefits to developing directly on a machine with SharePoint on it are so great now that I would recommend against &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/03/05/how-to-remote-debugging-a-web-application.aspx"&gt;remote debugging&lt;/a&gt; (although you still can).&amp;#160; The SharePoint Root (or the 12 hive as you called it) is now the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/sharepoint-2010-12-hive-2-14-hive.aspx"&gt;14 hive&lt;/a&gt; and is located at the predictable path below.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14&lt;/em&gt;&lt;/p&gt;  &lt;h5&gt;Coding the Web Part&lt;/h5&gt;  &lt;p&gt;Here is where things start to change.&amp;#160; Instead of creating a class library and adding references to the SharePoint DLLs, we simply use one of the new included SharePoint project templates as you can see here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroEmptyProject_43970EE2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroEmptyProject" border="0" alt="WebPartIntroEmptyProject" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroEmptyProject_thumb_138CBD61.png" width="519" height="369" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Start by using the Empty SharePoint Project template.&amp;#160; Also make sure you have it set to .NET Framework 3.5 as SharePoint does not run under .NET Framework 4.0 (don’t get me started).&amp;#160; You’ll notice you have many different project templates to choose from.&amp;#160; Most of these can also be used once you create an empty project.&amp;#160; On the next dialogue, pick farm solution.&amp;#160; I’ll go into the difference between sandboxed and farm solutions, but more than likely you are going to use farm solutions every time.&amp;#160; You also need to specify the URL to your server.&amp;#160; You can change that if you want but the default value will probably work for you in this case.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionType_19D393EF.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionType" border="0" alt="WebPartIntroSolutionType" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionType_thumb_4B5F0184.png" width="387" height="307" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This gives us a solution that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer_06B26743.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionExplorer" border="0" alt="WebPartIntroSolutionExplorer" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer_thumb_2661410B.png" width="163" height="156" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we are ready to build our new web part.&amp;#160; If you bring up the add new item context menu, you will see a number of choices for the types of new SharePoint Project Items (SPIs) that you can create.&amp;#160; We’re going to choose Web Part in this case.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSPI_6A357562.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSPI" border="0" alt="WebPartIntroSPI" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSPI_thumb_28BAC309.png" width="532" height="378" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;What is the &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/introducing-the-visual-web-part-in-sharepoint-2010.aspx"&gt;Visual Web Part&lt;/a&gt; you ask?&amp;#160; That’s just a user control which relates directly to my second most popular post on &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/11/18/introduction-to-sharepoint-development-deploy-a-user-control-in-sharepoint.aspx"&gt;How to Deploy a User Control&lt;/a&gt;.&amp;#160; Now we’re finally ready to add some code.&amp;#160; We’re just going to take our code from the WSS3 post and use it here.&lt;/p&gt;  &lt;div style="font-family:consolas;background:black;color:white;font-size:13pt;font-weight:bold;"&gt;   &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.ComponentModel;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; Microsoft.SharePoint;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; Microsoft.SharePoint.WebControls;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&lt;span style="color:#cc7832;"&gt;namespace&lt;/span&gt; SharePointProject1.TestWebPart&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; [ToolboxItemAttribute(&lt;span style="color:#cc7832;"&gt;false&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;public&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;class&lt;/span&gt; &lt;span style="color:#ffc66d;"&gt;TestWebPart&lt;/span&gt; : WebPart&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;public&lt;/span&gt; TestWebPart()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;protected&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;override&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; CreateChildControls()&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;base&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.CreateChildControls();&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Controls.Add(&lt;span style="color:#cc7832;"&gt;new&lt;/span&gt; Label() { Text = &lt;span style="color:#a5c25c;"&gt;&amp;quot;My Test SharePoint 2010 Web Part (Hello World)!&amp;quot;&lt;/span&gt; });&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;protected&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;override&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; RenderContents(HtmlTextWriter writer)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;base&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.RenderContents(writer);&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;   &lt;p&gt;The only line of code I added here was the line to add the label and set its text.&amp;#160; Everything else came from the template.&lt;/p&gt;  &lt;h5&gt;Describing the Web Part&lt;/h5&gt;  &lt;p&gt;In my WSS3 post, this is where I talked about building a .webpart file.&amp;#160; Well, you don’t need to worry about that any more as Visual Studio creates it for you.&amp;#160; Here is what solution explorer looks like after you add your first web part.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer2_43F31C0A.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroSolutionExplorer2" border="0" alt="WebPartIntroSolutionExplorer2" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroSolutionExplorer2_thumb_7C9DC617.png" width="213" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see the .webpart file is already there as well as an elements.xml file for a feature to deploy the web part.&amp;#160; The WSS3 post went on to talk about all of the things you need to know about building a feature.&amp;#160; This is still good stuff to know, but its already taken care of for you.&amp;#160; If you want to edit the basic feature information, just open it up in solution explorer and you get a nice new interface that looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroFeatureEditor_152D6368.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroFeatureEditor" border="0" alt="WebPartIntroFeatureEditor" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroFeatureEditor_thumb_14C13073.png" width="390" height="227" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I’m not going to waste space showing you the insides of the files it creates for you.&amp;#160; Just know it creates them for you and it saves you a ton of time.&lt;/p&gt;  &lt;h5&gt;Deploying via Solution Package&lt;/h5&gt;  &lt;p&gt;In my WSS3 post, I explained how to create a cab.ddf and manifest.xml file.&amp;#160; Well guest what?&amp;#160; That is taken care of for you now as well.&amp;#160; The Package.package file in the solution explorer provides another nice editor which allows you to choose with files go into the package.&amp;#160; You don’t have to keep track of a thing any more, it just builds the package and takes care of it for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroPackageEditor_42425036.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroPackageEditor" border="0" alt="WebPartIntroPackageEditor" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroPackageEditor_thumb_2CE49ACE.png" width="391" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;At this point, Visual Studio has created the .webpart file, the feature, and the solution package.&amp;#160; However, we still need to deploy it and if we could debug it that would be even cooler right?&amp;#160; Take a look at our new options in the Build menu.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBuildMenu_4574381E.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroBuildMenu" border="0" alt="WebPartIntroBuildMenu" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBuildMenu_thumb_59F9879C.png" width="244" height="192" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;   &lt;p&gt;We can build and rebuild just like any other project, but notice the options for Deploy, Package, and Retract.&amp;#160; Those are all SharePoint functions.&amp;#160; In this case, I want to deploy my solution.&amp;#160; Choosing deploy, we see the following in the output window.&lt;/p&gt;    &lt;p&gt;------ Build started: Project: SharePointProject1, Configuration: Debug Any CPU ------     &lt;br /&gt;&amp;#160; SharePointProject1 -&amp;gt; C:\Code\SharePointProject1\bin\Debug\SharePointProject1.dll      &lt;br /&gt;&amp;#160; Successfully created package at: C:\Code\SharePointProject1\bin\Debug\SharePointProject1.wsp      &lt;br /&gt;------ Deploy started: Project: SharePointProject1, Configuration: Debug Any CPU ------      &lt;br /&gt;Active Deployment Configuration: Default      &lt;br /&gt;Run Pre-Deployment Command:      &lt;br /&gt;&amp;#160; Skipping deployment step because a pre-deployment command is not specified.      &lt;br /&gt;Recycle IIS Application Pool:      &lt;br /&gt;&amp;#160; Recycling IIS application pool &amp;#39;SharePoint - 80&amp;#39;...      &lt;br /&gt;Retract Solution:      &lt;br /&gt;&amp;#160; Skipping package retraction because no matching package on the server was found.      &lt;br /&gt;Add Solution:      &lt;br /&gt;&amp;#160; Adding solution &amp;#39;SharePointProject1.wsp&amp;#39;...      &lt;br /&gt;&amp;#160; Deploying solution &amp;#39;SharePointProject1.wsp&amp;#39;...      &lt;br /&gt;Activate Features:      &lt;br /&gt;&amp;#160; Activating feature &amp;#39;Feature1&amp;#39; ...      &lt;br /&gt;Run Post-Deployment Command:      &lt;br /&gt;&amp;#160; Skipping deployment step because a post-deployment command is not specified.      &lt;br /&gt;========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========      &lt;br /&gt;========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========      &lt;br /&gt;&lt;/p&gt;    &lt;p&gt;From inspecting the text of the log, you can see that Visual Studio compiled, created a package, reset my Application Pool, Added the Solution, Deployed the Solution, and activated the feature.&amp;#160; Let’s check SharePoint and see if it’s really there.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroGallery_728924EC.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroGallery" border="0" alt="WebPartIntroGallery" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroGallery_thumb_2B33CEFA.png" width="514" height="23" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Checking the web part gallery, we see our .webpart file.&amp;#160; Let’s add it to a page and see how it looks.&amp;#160; Edit any page and use add a web part and you will see the new interface for choosing a web part.&amp;#160; It puts it in the Custom group by default.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroAddWebPart_5FD42B35.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroAddWebPart" border="0" alt="WebPartIntroAddWebPart" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroAddWebPart_thumb_0A405C53.png" width="553" height="306" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;One you hit and add finish editing, we see the web part working correctly.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroWorking_30A23F9E.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroWorking" border="0" alt="WebPartIntroWorking" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroWorking_thumb_173A3C64.png" width="555" height="211" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;You have to admit this is quite a bit easier than deploying a web part in SharePoint 3.&amp;#160; What if you want to debug though?&amp;#160; No problem.&amp;#160; Just set a breakpoint and choose debug from the build menu like you would any other type of project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBreakPointHit_5DB72C6C.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="WebPartIntroBreakPointHit" border="0" alt="WebPartIntroBreakPointHit" src="http://www.dotnetmafia.com/blogs/dotnettipoftheday/WebPartIntroBreakPointHit_thumb_48597704.png" width="563" height="76" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As I mentioned earlier, if you are familiar with SharePoint 2010, this is nothing new to you.&amp;#160; However, my point today is for those who shied away from SharePoint in the past because the development experience was far from optimal.&amp;#160; Try it for yourself and you will see how easy it is to get up and running with your code.&amp;#160; Even with pictures this post is half the size of the WSS3 post.&amp;#160; That’s because it really is just that easy.&amp;#160; I really think Visual Studio 2010 will open the way for a new round of SharePoint developers.&amp;#160; Try it out today.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=2748" width="1" height="1"&gt;</description><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Feature/default.aspx">Feature</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/WebPart/default.aspx">WebPart</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Solution/default.aspx">Solution</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SharePoint+2010/default.aspx">SharePoint 2010</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SPC09/default.aspx">SPC09</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SP2010+Beta/default.aspx">SP2010 Beta</category></item><item><title>Troubleshooting Sandboxed Solutions in SharePoint 2010</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/30/troubleshooting-sandboxed-solutions-in-sharepoint-2010.aspx</link><pubDate>Mon, 30 Nov 2009 19:08:00 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:1132</guid><dc:creator>CoreyRoth</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.dotnetmafia.com/blogs/dotnettipoftheday/rsscomments.aspx?PostID=1132</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/11/30/troubleshooting-sandboxed-solutions-in-sharepoint-2010.aspx#comments</comments><description>&lt;p&gt;I have a talk coming up on Code Access Security at SharePoint Saturday Kansas City next month so I have been investigating sandboxed solutions quite a bit.&amp;#160; After all, sandboxed solutions are just another flavor of using CAS with some additional things thrown in.&amp;#160; However, after I got my SharePoint server installed and configured, I found that sandboxed solutions were not working.&amp;#160; When I configured my solution to use the sandbox and tried to deploy it, I got the following error.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Error occurred in deployment step &amp;#39;Activate Features&amp;#39;: Cannot start service SPUserCodeV4 on computer &amp;#39;servername&amp;#39;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;I found that to be odd, so I decided to do some looking around.&amp;#160; I ended up in the Windows Services MMC snapin and found that the service called &lt;em&gt;Windows SharePoint Services UserCode Host v4&lt;/em&gt; was in fact set to disabled.&amp;#160; I changed this to automatic and started the service up.&amp;#160; I tried to deploy again, but unfortunately things still weren’t working.&amp;#160; Here is the error I got this time.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Error occurred in deployment step &amp;#39;Activate Features&amp;#39;: This feature cannot be activated at this time. The contents of the feature&amp;#39;s solution requires the Solution Sandbox service to be running.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;This one took a little bit more digging, but I ended up going to Central Administration and looking at the Services on Server page.&amp;#160; I thought what I needed would be under Service Applications, but that was not the case.&amp;#160; I took a look at Services on Server and quickly discovered that the &lt;em&gt;Microsoft SharePoint Foundation User Code Service&lt;/em&gt; had not been started.&amp;#160; I started the service and then I tried to deploy again and the errors went away and my sandboxed web part worked as expected.&amp;#160; I’m not sure why neither of these started.&amp;#160; It could be because I don’t have enough memory allocated to the virtual machine or maybe it’s always disabled by default.&amp;#160; Anyhow, be sure and check these two things before you try to work in the sandbox.&lt;/p&gt;  &lt;p&gt;UPDATE: &lt;a href="http://twitter.com/MSwannMSFT"&gt;@MSwannMSFT&lt;/a&gt; confirmed for me that this is by design.&amp;#160; It’s disabled for performance and security since it spins up three new processes.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=1132" 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/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><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Sandboxed+Solution/default.aspx">Sandboxed Solution</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>Introducing the Visual Web Part in SharePoint 2010</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/introducing-the-visual-web-part-in-sharepoint-2010.aspx</link><pubDate>Tue, 20 Oct 2009 21:38:19 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:1011</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=1011</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/10/20/introducing-the-visual-web-part-in-sharepoint-2010.aspx#comments</comments><description>&lt;p&gt;You might have seen that there is a new designer for working with web parts in Visual Studio 2010.&amp;#160; This is actually, not quite the case, so I thought I would share with you how it actually works.&amp;#160; When you use the Visual Web Part SPI (SharePoint Project Item), it will create a number of files for you: a .cs file, a .webpart file, an elements.xml file, and a .ascx file.&amp;#160; That’s right, it creates an ASP.NET user control.&amp;#160; Now, the Visual Studio interface does a nice job of grouping all of the files together.&amp;#160; When you open the designer on the web part, you in fact just open the designer for the user control.&amp;#160; &lt;/p&gt;  &lt;p&gt;So now you might be thinking, how does this work?&amp;#160; Well no SharePoint can’t host user controls directly still. In fact all it does is create a simple web part with a Page.LoadControl() method pointing at our user control.&amp;#160; This in fact is the same method we’ve been using for years to get user controls into SharePoint.&amp;#160; I don’t really see this as an issue though, since Visual Studio does a great job making it painless to deploy these now and use them inside SharePoint.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=1011" 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/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/SPC09/default.aspx">SPC09</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/SP2010+Beta/default.aspx">SP2010 Beta</category></item></channel></rss>