<?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] : Enterprise Library</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/Enterprise+Library/default.aspx</link><description>Tags: Enterprise Library</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Linq to XML and Deleting Lists on Feature Deactivation</title><link>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/09/24/linq-to-xml-and-deleting-lists-on-feature-deactivation.aspx</link><pubDate>Thu, 24 Sep 2009 20:04:04 GMT</pubDate><guid isPermaLink="false">ceb7fe2a-c56b-4d85-99e6-8dd548580538:976</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=976</wfw:commentRss><comments>http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/09/24/linq-to-xml-and-deleting-lists-on-feature-deactivation.aspx#comments</comments><description>&lt;p&gt;A few months ago, I discussed how to use LINQ to XML to parse your elements.xml file to &lt;a href="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/02/16/linq-to-xml-and-deleting-files-on-feature-deactivation.aspx"&gt;delete any files&lt;/a&gt; that you may have deployed on feature activation.&amp;#160; Today I have decided to reuse this concept to delete any lists that I have created when I deactivate a feature?&amp;#160; Now you may ask, “why would I want to delete a list when a feature is deactivated?&amp;#160; I’ll lose all of my data in that list!”&amp;#160; My answer is: Yes, of course you will, but sometimes when building a feature to deploy a list(s), you want to delete the list each time before you deploy a new version of it.&amp;#160; During development this is a huge time saver.&amp;#160; Right now, I am working on a feature that deploys four document libraries.&amp;#160; This means I have to manually delete each one.&amp;#160; That is a huge waste of time, but what is nice is that we can reuse the concept above with LINQ to XML and delete lists instead.&amp;#160; &lt;/p&gt;  &lt;p&gt;The code is quite similar.&amp;#160; Have a look.&amp;#160; We first, write some code to get the path to the elements.xml file.&amp;#160; This code snippet assumes, it is always named Elements.xml.&amp;#160; Maybe in the future, I will have it look in the feature.xml file, get all of the ElementManifest definitions and then delete whatever it finds in each file.&amp;#160; For now though, we assume, you can change the path as needed.&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;public&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;override&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; FeatureDeactivating(SPFeatureReceiverProperties properties)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;using&lt;/span&gt; (SPWeb currentSite = (SPWeb)properties.Feature.Parent)&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;string&lt;/span&gt; elementsPath = &lt;span style="color:#cc7832;"&gt;string&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.Format(&lt;/span&gt;&lt;span style="color:#a31515;font-weight:normal;"&gt;@&amp;quot;{0}\FEATURES\{1}\Elements.xml&amp;quot;&lt;/span&gt;, SPUtility.GetGenericSetupPath(&lt;span style="color:#a5c25c;"&gt;&amp;quot;Template&amp;quot;&lt;/span&gt;), properties.Definition.DisplayName);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DeleteLists(currentSite, elementsPath);&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;From here, it passes a reference to the current SPWeb and the path to the XML document.&amp;#160; The path to the elements.xml file is used to populate an XDocument which we can then query with LINQ to XML.&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;private&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;void&lt;/span&gt; DeleteLists(SPWeb currentSite, &lt;span style="color:#cc7832;"&gt;string&lt;/span&gt; elementsPath)&lt;/p&gt;    &lt;p style="margin:0px;"&gt;{&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#cc7832;"&gt;try&lt;/span&gt;&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; XDocument elementsXml = XDocument.Load(elementsPath);&lt;/p&gt;    &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; XNamespace sharePointNamespace = &lt;span style="color:#a5c25c;"&gt;&amp;quot;http://schemas.microsoft.com/sharepoint/&amp;quot;&lt;/span&gt;;&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:green;"&gt;// get each URL to each list&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;span style="color:#cc7832;"&gt;var&lt;/span&gt; listInstances = &lt;span style="color:#cc7832;"&gt;from&lt;/span&gt; module &lt;span style="color:#cc7832;"&gt;in&lt;/span&gt; elementsXml.Root.Elements(sharePointNamespace + &lt;span style="color:#a5c25c;"&gt;&amp;quot;ListInstance&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;&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 style="color:#cc7832;"&gt;select&lt;/span&gt; &lt;span style="color:#cc7832;"&gt;new&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;&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;/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;&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; ListUrl = (module.Attributes(&lt;span style="color:#a5c25c;"&gt;&amp;quot;Url&amp;quot;&lt;/span&gt;).Any()) ? module.Attribute(&lt;span style="color:#a5c25c;"&gt;&amp;quot;Url&amp;quot;&lt;/span&gt;).Value : &lt;span style="color:#cc7832;"&gt;null&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;&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;/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:green;"&gt;// iterate through each list and delete it&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;span style="color:#cc7832;"&gt;foreach&lt;/span&gt; (&lt;span style="color:#cc7832;"&gt;var&lt;/span&gt; listInstance &lt;span style="color:#cc7832;"&gt;in&lt;/span&gt; listInstances)&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;try&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; {&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;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SPList currentList = currentSite.GetList(&lt;span style="color:#cc7832;"&gt;string&lt;/span&gt;&lt;span style="font-weight:normal;"&gt;.Format(&lt;/span&gt;&lt;span style="color:#a5c25c;"&gt;&amp;quot;{0}/{1}&amp;quot;&lt;/span&gt;, currentSite.Url, listInstance.ListUrl));&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;&amp;#160;&amp;#160;&amp;#160;&amp;#160; currentList.Delete();&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;/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;catch&lt;/span&gt; (System.IO.&lt;span style="color:#ffc66d;"&gt;FileNotFoundException&lt;/span&gt; e)&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;/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;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// this exception is thrown if the list does not exist&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; }&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:green;"&gt;// update the site&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; currentSite.Update();&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; &lt;span style="color:#cc7832;"&gt;catch&lt;/span&gt;&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; }&lt;/p&gt;    &lt;p style="margin:0px;"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;This code is quite similar to that used in my other post, however instead of looking for Module elements we are looking for &lt;em&gt;ListInstance&lt;/em&gt; elements.&amp;#160; It creates a list of those Urls to each list and iterates through them.&amp;#160; For each list it finds, it deletes the list.&amp;#160;&amp;#160; I’ve written code in the past to manually delete lists, I create by name.&amp;#160; That works fine, but the name of each list has to be maintained.&amp;#160; Now, I just attach this to any feature I am working on and it deletes any list (or lists) that I throw at it.&amp;#160; More than likely this isn’t something you want once you go to production, but it will save you a ton of time during development.&lt;/p&gt;&lt;img src="http://www.dotnetmafia.com/aggbug.aspx?PostID=976" 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+XML/default.aspx">LINQ to XML</category><category domain="http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/tags/LINQ/default.aspx">LINQ</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/Enterprise+Library/default.aspx">Enterprise Library</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>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></channel></rss>