<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6188351627206500991</id><updated>2011-09-29T11:22:16.858+01:00</updated><category term='Tools'/><category term='Content Query Web Parts'/><category term='Development'/><category term='SharePoint 2007'/><category term='General'/><category term='Customisation'/><title type='text'>GEMSolution Blog</title><subtitle type='html'>"Share"....thats the "Point".   
A Blog dedicated to SharePoint 2010, 2007 and .Net Development</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-7435604565796501865</id><published>2011-09-28T18:18:00.000+01:00</published><updated>2011-09-28T18:31:16.243+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='Content Query Web Parts'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Displaying a User field in a Content Query Web part (CQWP)</title><content type='html'>&lt;p&gt;Well it has been a little while since i have posted but hopefully now i will pick up where i left off&amp;#160; with the addition of the SharePoint 2010 world too.&lt;/p&gt;  &lt;p&gt;I have been working on a 2007 environment recently and in particular a content query web part which is being used to display document information across an entire site collection based on a hierarchy of content types, so i set about the normal method of adding the CQWP to a page, exporting it, customising, adding in the custom xsl (ItemStyle, ContentQueryMain and Header) and then uploading to the webpart gallery and adding to a page.&lt;/p&gt;  &lt;p&gt;All pretty easy stuff really…………….well.&lt;/p&gt;  &lt;p&gt;A problem came about when i tried adding in a Site Column called “Document Owner” which was of type User.&amp;#160; I went about adding in the column to the CommonViewFields section of the .webpart, adding in a reference to Document_x0020_Owner,User;.&amp;#160; This caused the webpart to throw an error and fail completely.&amp;#160; I then searched many forums and blogs and tried a multitude of “solutions” including setting CommonViewFields reference to Document_x0020_Owner,Text; also trying the viewfieldsoverride property which turned out to be too restrictive, and nothing worked for me.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;After some more frustrating investigation and trials and errors, the answer as unbelievably simple.&amp;#160; Omit the identifier from the CommonViewFields property so it only looks like this.&lt;/p&gt;  &lt;p&gt;&amp;lt;property name=&amp;quot;CommonViewFields&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;Document_x0020_Owner;&amp;lt;/property&amp;gt;&lt;/p&gt;  &lt;p&gt;I also put in an entry into the DataColumnRenames property too, like so to make it easier to pick up in the xsl&lt;/p&gt;  &lt;p&gt;&amp;lt;property name=&amp;quot;DataColumnRenames&amp;quot; type=&amp;quot;string&amp;quot;&amp;gt;Document_x0020_Owner,DocumentOwner;&amp;lt;/property&amp;gt;&lt;/p&gt;  &lt;p&gt;then in your ItemStyle.xsl file, make reference to this field as follows (I setup a variable to achieve this), this removes the ID from the output which normally appears as 1;#morgan,gavin&lt;/p&gt;  &lt;p&gt;&amp;lt;xsl:variable name=&amp;quot;DocumentOwner&amp;quot;&amp;gt;&amp;#160; &lt;br /&gt;&amp;lt;xsl:value-of select=&amp;quot;substring-after@DocumentOwner, ';#')&amp;quot; /&amp;gt;&amp;lt;/xsl:variable&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;xsl:value-of select=&amp;quot;$DocumentOwner&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;Hope that saves some others pain…….&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-7435604565796501865?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/7435604565796501865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2011/09/displaying-user-field-in-content-query.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/7435604565796501865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/7435604565796501865'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2011/09/displaying-user-field-in-content-query.html' title='Displaying a User field in a Content Query Web part (CQWP)'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-4444234777525593257</id><published>2010-05-13T09:04:00.000+01:00</published><updated>2010-08-11T09:05:45.219+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>SharePoint Designer 2007 workflow SendEmail notification failed for SharePoint Groups</title><content type='html'>&lt;p&gt;Came across a problem the other day where i had a SharePoint Designer workflow which sent a notification out to a SharePoint Group but failed.&amp;#160;&amp;#160; The workflow was fine sending out notifications to individuals, it just wouldn’t send out to a group, it would report an error “The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly”&amp;#160; which is a bit of a red herring as there is nothing wrong with the email settings.&lt;/p&gt;  &lt;p&gt;After a bit of digging around, i found the following fixes which resolved the issue.&amp;#160; It was actually to do with some of the permissions of the group I was using to send the email to, so you need to amend some of the settings on the group.&lt;/p&gt;  &lt;p&gt;Firstly, Navigate to the site in question, click on Site Actions -&amp;gt; Site Settings -&amp;gt; People and Groups. Select the group that you are using to send the email to from the left navigation.&amp;#160; Then click on Settings -&amp;gt; Group Settings. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_XXL39Egrp5Q/TGJZuIY4X9I/AAAAAAAAACw/JiPk-1DBqOI/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh3.ggpht.com/_XXL39Egrp5Q/TGJZvr4iKAI/AAAAAAAAAC0/PlvIXrJgDyM/clip_image002_thumb.jpg?imgmax=800" width="244" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Secondly, make sure that the group that you are using to send an email to has at least “Read” permissions on the Site where you created your SharePoint designer workflow.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_XXL39Egrp5Q/TGJZxPO9IkI/AAAAAAAAAC4/b6tbQ2jWqFI/s1600-h/clip_image002%5B6%5D%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[6]" border="0" alt="clip_image002[6]" src="http://lh6.ggpht.com/_XXL39Egrp5Q/TGJZyvZBMJI/AAAAAAAAAC8/4EMymwfMLEs/clip_image002%5B6%5D_thumb%5B1%5D.jpg?imgmax=800" width="504" height="121" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally, within the Group settings section, make sure that “Everyone” can view the membership of the group.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_XXL39Egrp5Q/TGJZ0oO58cI/AAAAAAAAADA/u4EhvJ-ZZH0/s1600-h/clip_image002%5B4%5D%5B6%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/TGJZ1-xZC7I/AAAAAAAAADE/Oim5s98W7K0/clip_image002%5B4%5D_thumb%5B4%5D.jpg?imgmax=800" width="504" height="76" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;hope that helps a few people out….&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-4444234777525593257?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/4444234777525593257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/05/sharepoint-designer-2007-workflow.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4444234777525593257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4444234777525593257'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/05/sharepoint-designer-2007-workflow.html' title='SharePoint Designer 2007 workflow SendEmail notification failed for SharePoint Groups'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_XXL39Egrp5Q/TGJZvr4iKAI/AAAAAAAAAC0/PlvIXrJgDyM/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-3697259435659396609</id><published>2010-04-22T09:40:00.000+01:00</published><updated>2010-07-23T09:41:26.168+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Recurring Meeting Workspace date picker JavaScript error</title><content type='html'>&lt;p&gt;If you have a custom master page on your meeting workspaces (replaced MWSDefault.master), then you may encounter a JavaScript error for selecting a data from the left navigation if you setup a recurring meeting for that workspace.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_XXL39Egrp5Q/TElVsN-dYXI/AAAAAAAAACo/Y1yPzVQnn3Y/s1600-h/clip_image002%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh6.ggpht.com/_XXL39Egrp5Q/TElVtIvUmEI/AAAAAAAAACs/QHupi3EYVmY/clip_image002_thumb%5B1%5D.jpg?imgmax=800" width="399" height="173" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To fix this issue open the custom master page (in SharePoint Designer if need be) and insert the following line below all of the other Register Tags and before the HTML tag starts&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Register Tagprefix=&amp;quot;Meetings&amp;quot; Namespace=&amp;quot;Microsoft.SharePoint.Meetings&amp;quot; Assembly=&amp;quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;next insert the following line directly below the &amp;lt;Body&amp;gt; tag.&lt;/p&gt;  &lt;p&gt;&amp;lt;Meetings:PropertyBag runat=&amp;quot;server&amp;quot;/&amp;gt;&lt;/p&gt;  &lt;p&gt;After this publish your master page and all meeting workspaces should now work.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-3697259435659396609?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/3697259435659396609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/04/recurring-meeting-workspace-date-picker.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3697259435659396609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3697259435659396609'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/04/recurring-meeting-workspace-date-picker.html' title='Recurring Meeting Workspace date picker JavaScript error'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_XXL39Egrp5Q/TElVtIvUmEI/AAAAAAAAACs/QHupi3EYVmY/s72-c/clip_image002_thumb%5B1%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-5197217696406892680</id><published>2010-03-08T17:06:00.001Z</published><updated>2010-03-08T17:18:45.314Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>GEMSolution Blog has Switched to Google Blogger</title><content type='html'>&lt;p&gt;GEMSolution Blog “Share”….that’s the “Point” has now moved to Google’s Blogger tool.&lt;/p&gt;&lt;p&gt;I will shortly be uploading all historic blogs from the old blog site and putting a redirect in place on the old blog site so people are redirected here automatically.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-5197217696406892680?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/5197217696406892680/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/03/gemsolution-blog-has-switched-to-google.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5197217696406892680'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5197217696406892680'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/03/gemsolution-blog-has-switched-to-google.html' title='GEMSolution Blog has Switched to Google Blogger'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-5366271756989160922</id><published>2010-01-20T10:08:00.001Z</published><updated>2010-03-08T20:51:16.074Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Contains operator missing in Advance Search Web Part</title><content type='html'>&lt;p&gt;This is an old topic, and i know it has been covered by some other people, but it is one i keep having to rectify in various client environments, so thought i would give myself an easy reference point for it rather than keep trawling the web each time.&lt;/p&gt;  &lt;p&gt;So you have added the advance search Web Part to a page and the only two options which exist in the operator drop down (see below) are “Equals” and “Does not equal”.&amp;#160; So where has the “contains” and “does not contain” operator gone.&amp;#160;&amp;#160; &lt;/p&gt; &lt;a name='more'&gt;&lt;/a&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_XXL39Egrp5Q/S5U0CJV7u0I/AAAAAAAAABE/eZwz0coh2_0/s1600-h/clip_image0023.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh6.ggpht.com/_XXL39Egrp5Q/S5U0DBLEIrI/AAAAAAAAABI/DwCyb3PhWls/clip_image002_thumb.jpg?imgmax=800" width="244" height="121" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The explanation of why it has disappeared could be due to an MS infrastructure update to increase performance for search.&lt;/p&gt;  &lt;p&gt;Well, to restore this follow the instructions below.&lt;/p&gt;  &lt;p&gt;1. If the page is not already in Edit mode, click on Site Actions and then Edit Page.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_XXL39Egrp5Q/S5U0D4pwB8I/AAAAAAAAABM/IKDmu6fyOMA/s1600-h/clip_image00242.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0Ek2zxNI/AAAAAAAAABQ/8WW9lrpMsdM/clip_image0024_thumb.jpg?imgmax=800" width="244" height="178" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. On the Advanced Search Web Part click on the Edit and then Modify Shared Web Part&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_XXL39Egrp5Q/S5U0FHS6mkI/AAAAAAAAABU/oSGJzxWx63Q/s1600-h/clip_image00262.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[6]" border="0" alt="clip_image002[6]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0Fx-OnTI/AAAAAAAAABY/MYoPtaftDRI/clip_image0026_thumb.jpg?imgmax=800" width="228" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. From the Web Part property section on the right,&amp;#160;&amp;#160; Scroll down to the properties section and then click on the … button next to the properties section&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_XXL39Egrp5Q/S5U0G7AEPbI/AAAAAAAAABc/trTZcFIn3Pg/s1600-h/clip_image00282.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[8]" border="0" alt="clip_image002[8]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0HxuuXfI/AAAAAAAAABg/8XAjczkBRCo/clip_image0028_thumb.jpg?imgmax=800" width="186" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;4. At the top of the Dialogue box, you may have one of 2 scenarios.&amp;#160; Either the following appears&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_XXL39Egrp5Q/S5U0J-q5uxI/AAAAAAAAABs/9DTRQg_TVoE/s1600-h/clip_image002102.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[10]" border="0" alt="clip_image002[10]" src="http://lh4.ggpht.com/_XXL39Egrp5Q/S5U0K1zrUPI/AAAAAAAAABw/3mn8AIv2kjM/clip_image00210_thumb.jpg?imgmax=800" width="244" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;or there is no Element for the AllowOpContains.&amp;#160;&amp;#160; If you have the Element, then simply change the False value to True.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_XXL39Egrp5Q/S5U0Nvl8XNI/AAAAAAAAAB0/mweLJcntQlY/s1600-h/clip_image002122.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[12]" border="0" alt="clip_image002[12]" src="http://lh6.ggpht.com/_XXL39Egrp5Q/S5U0OmBGuAI/AAAAAAAAAB4/zTUHuOO60So/clip_image00212_thumb.jpg?imgmax=800" width="244" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;if you do not have the element at all paste the following directly inside&amp;#160; the root element. &lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 450px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Option&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;AllowOpContains&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Value&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;True&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;It should then look like this.&amp;#160; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0Pns3oCI/AAAAAAAAAB8/siB2UHvshD0/s1600-h/clip_image002142.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[14]" border="0" alt="clip_image002[14]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0QyoqgzI/AAAAAAAAACA/kyejGv0k_TM/clip_image00214_thumb.jpg?imgmax=800" width="244" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;5. Now click ok and then Apply or Ok on the Web Part properties panel, and check you have the options as shown below.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0Rz2eIKI/AAAAAAAAACE/ZjC_6Vn5Y4g/s1600-h/clip_image002162.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002[16]" border="0" alt="clip_image002[16]" src="http://lh3.ggpht.com/_XXL39Egrp5Q/S5U0Sdq0w_I/AAAAAAAAACI/Zff0J_BkfWM/clip_image00216_thumb.jpg?imgmax=800" width="244" height="129" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-5366271756989160922?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/5366271756989160922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/01/contains-operator-missing-in-advance.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5366271756989160922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5366271756989160922'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/01/contains-operator-missing-in-advance.html' title='Contains operator missing in Advance Search Web Part'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_XXL39Egrp5Q/S5U0DBLEIrI/AAAAAAAAABI/DwCyb3PhWls/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-5746968718986613607</id><published>2010-01-04T09:42:00.000Z</published><updated>2010-03-08T17:27:37.604Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Happy New Year</title><content type='html'>&lt;p&gt;&lt;font size="2" face="cal"&gt;Just thought I'd send a quick post to wish everyone who reads my Blog a very Happy New Year.&amp;#160; I am looking forward to an exciting 2010 with plenty of new technologies to dive into with SharePoint 2010 and Visual Studio 2010 at the top of my list. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Over the Christmas period i managed to get a SharePoint 2010 beta server up and running so i will be putting up some posts on my findings whilst playing around.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;I Will also be looking into Visual Studio 2010 and how well it integrates and caters for SharePoint development.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Watch this space………..&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-5746968718986613607?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/5746968718986613607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/01/happy-new-year.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5746968718986613607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5746968718986613607'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/01/happy-new-year.html' title='Happy New Year'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-6897958492811768982</id><published>2009-11-13T08:26:00.001Z</published><updated>2010-03-08T20:34:13.586Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Setting ModerationInformation.Status back to pending removes author/creator permissions</title><content type='html'>Here’s the scenario – I have a visual studio sequential workflow on a list (not document library) which has a 2 stage approval process.&amp;nbsp; The request was to use the standard OOB approve/reject mechanism rather than tasks, so for the first stage of approval, the approver would select Approve/Reject from a list item.&amp;nbsp; Once the first stage approver approves the item, the item should NOT be approved and live, but still pending and an email sent to the 2nd level approver to make the ultimate decision of making the item live.&amp;nbsp; Once the 2nd stage approver approves the item the item then becomes Approved and Published for all to see.&lt;br /&gt;I created a Visual Studio Sequential Workflow and created separate routes through workflow based on who updated the List Item.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_XXL39Egrp5Q/S5Ve-5hC65I/AAAAAAAAACQ/Sl08aBMwCMI/s1600-h/image3.png"&gt;&lt;img alt="image" border="0" height="113" src="http://lh5.ggpht.com/_XXL39Egrp5Q/S5Ve_mnJYmI/AAAAAAAAACU/C7twKsRptQs/image_thumb1.png?imgmax=800" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="432" /&gt;&lt;/a&gt;&lt;br /&gt;In code, if the item was approved by the 1st stage approver&amp;nbsp; i would reset the ModerationInformation.Status back to pending, my code was simple and as follows;&lt;br /&gt;&lt;pre style="background-color: #fbfbfb; border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; border-right: #cecece 1px solid; border-top: #cecece 1px solid; min-height: 40px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 400px;"&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;1: &lt;span style="color: blue;"&gt;this&lt;/span&gt;.workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Pending;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;2: &lt;span style="color: blue;"&gt;this&lt;/span&gt;.workflowProperties.Item.Update();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;3: &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;4: &lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To troubleshoot this, i took to using Powershell and SharePoint Manager from codeplex to see what was happening to my list item.&amp;nbsp;&amp;nbsp; Throughout, the creator and author field was not changed from the person that created, yet as soon as i set the moderationinformation.status back to pending, the creator of the item lost ALL permissions to even view the item.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I had tried the following to rectify this but none worked;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-size: x-small;"&gt;I have tried all combinations of Update(), SystemUpdate(), SystemUpdate(false), SystemUpdate(true), UpdateOverwriteVersion() when saving the list item and none of them had any effect.&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-size: x-small;"&gt;I tried to up the version number so that the version of the list item that was being approved and set back to pending was version 2.0 to ensure that the Creator/Author was preserved.&lt;/span&gt; &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;I have only found one way in which to rectify this problem and that is to re-assign the roledefinitionsbinding for that user to a level which allows them to edit/update the item again.&amp;nbsp; I did this using the following code.&amp;nbsp;&amp;nbsp; Just one more thing, i had also disabledeventfiring in my workflow so i can be sure that events dont keep firing and updating the item.&amp;nbsp;&amp;nbsp; This is how i did that in code;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background-color: #fbfbfb; border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; border-right: #cecece 1px solid; border-top: #cecece 1px solid; min-height: 40px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 450px;"&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;1: SPListItem currentItem = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.workflowProperties.Item;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;2: &lt;span style="color: green;"&gt;//Get the Full Control Role Definition&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;3: SPRoleDefinitionCollection roleDefs = &lt;span style="color: blue;"&gt;this&lt;/span&gt;.workflowProperties.Web.RoleDefinitions;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;4: SPRoleDefinition roleFullControl = roleDefs["&lt;span style="color: darkred;"&gt;Full Control&lt;/span&gt;"];&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;5: &lt;span style="color: green;"&gt;//Get the current items role assignments&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;6: SPRoleAssignmentCollection rolesInList = currentItem.RoleAssignments;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;7: &lt;span style="color: green;"&gt;//iterate through and find the creator users role assigment&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;8: &lt;span style="color: blue;"&gt;foreach&lt;/span&gt;(SPRoleAssignment role &lt;span style="color: blue;"&gt;in&lt;/span&gt; rolesInList)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;9: {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;10:   &lt;span style="color: blue;"&gt;string&lt;/span&gt; createdByString = currentItem["&lt;span style="color: darkred;"&gt;Created By&lt;/span&gt;"].ToString();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;11:   &lt;span style="color: blue;"&gt;int&lt;/span&gt; indexOfSemiColon = createdByString.IndexOf("&lt;span style="color: darkred;"&gt;;&lt;/span&gt;");&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;12:   &lt;span style="color: blue;"&gt;int&lt;/span&gt; createdById = Int32.Parse(createdByString.Substring(0, indexOfSemiColon));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;13:   &lt;span style="color: blue;"&gt;if&lt;/span&gt;(role.Member.ID == createdById)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;14:   {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;15:     &lt;span style="color: blue;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;16:     {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;17:       &lt;span style="color: green;"&gt;//firstly remove any role bindings the add in whatever level you require&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;18:       role.RoleDefinitionBindings.RemoveAll();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;19:       role.RoleDefinitionBingings.Add(roleFullControl);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;20:       role.Update();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;21:     }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;22:     &lt;span style="color: blue;"&gt;catch&lt;/span&gt;{}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: white; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;23:   }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 12px; margin: 0em; width: 100%;"&gt;24: }&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This solved my problem, but i am not saying this is the correct solution in all cases.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If anyone comes up with an answer as to why this happens, feel free to post a reply to this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-6897958492811768982?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/6897958492811768982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2009/11/setting-moderationinformationstatus.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/6897958492811768982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/6897958492811768982'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2009/11/setting-moderationinformationstatus.html' title='Setting ModerationInformation.Status back to pending removes author/creator permissions'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_XXL39Egrp5Q/S5Ve_mnJYmI/AAAAAAAAACU/C7twKsRptQs/s72-c/image_thumb1.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-4521547457829803345</id><published>2009-10-31T09:39:00.001Z</published><updated>2010-03-08T20:53:05.491Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>SPDisposeCheck Error workaround</title><content type='html'>I use the very useful SPDisposeCheck tool to check my assemblies using the SharePoint API to make sure i have not left any SharePoint objects open which could cause potential memory leaks. &lt;a name='more'&gt;&lt;/a&gt;  &lt;br /&gt;I encounter issues using the output to xml file “–xml” switch on the tool where it simply crashes at the point of “Processing Method Traces”.&amp;#160; I am not sure if there is an updated version out there to fix this but should you want to get the output to a file rather than the command window, i use a workaround to which outputs (pipes) the command window to a file by using the &amp;gt; command, so your command should look something like this.   &lt;br /&gt;SPDisposeCheck “&amp;lt;mydllFileOrDirectory&amp;gt;” –debug&amp;#160; &lt;strong&gt;&amp;gt;&lt;/strong&gt;”&amp;lt;outputdirectory&amp;gt;outputtfile.txt”   &lt;br /&gt;Hope that helps if people want to save the output.     &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-4521547457829803345?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/4521547457829803345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2009/10/spdisposecheck-error-workaround.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4521547457829803345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4521547457829803345'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2009/10/spdisposecheck-error-workaround.html' title='SPDisposeCheck Error workaround'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-6347267981604264578</id><published>2009-09-14T10:32:00.000+01:00</published><updated>2010-03-16T09:32:50.133Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Finally got round to taking the 70-541 MCTS WSS 3.0 Developer Exam</title><content type='html'>&lt;p&gt;I finally got round to taking the 70-541 MCTS Microsoft Windows SharePoint Services 3.0 – Application Developer exam today and passed with a score of 895.&lt;/p&gt;  &lt;p&gt;The exam content was pretty much what everyone out there is blogging about with some added questions which apparently do not contribute to your score in order for Microsoft to test out some new questions.&amp;#160; Completed it in just over an hour.&lt;/p&gt;  &lt;p&gt;Having worked with SharePoint since its Beta days back in October 2006, i didn't think it really tested or was a reflection on my real world experience of development within the WSS space.&amp;#160; &lt;/p&gt;  &lt;p&gt;I used the Inside &lt;a href="http://www.amazon.co.uk/Microsoft-Windows-SharePoint-Services-Developer/dp/0735623201/ref=sr_1_2?ie=UTF8&amp;amp;s=books&amp;amp;qid=1254748136&amp;amp;sr=1-2" target="_blank"&gt;Microsoft SharePoint Services 3.0&lt;/a&gt; book (Ted Pattison), which i did find useful and then a number of Visual Cert Exams from various places out on the web.&amp;#160; All pretty useful for passing the exam.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-6347267981604264578?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/6347267981604264578/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2009/09/finally-got-round-to-taking-70-541-mcts_14.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/6347267981604264578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/6347267981604264578'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2009/09/finally-got-round-to-taking-70-541-mcts_14.html' title='Finally got round to taking the 70-541 MCTS WSS 3.0 Developer Exam'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-4266586758973028098</id><published>2009-04-07T10:30:00.000+01:00</published><updated>2010-03-16T09:33:20.279Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Fun with SPFieldUserValueCollection</title><content type='html'>&lt;p&gt;I have been searching around to see the various ways in which people are retrieving Users and Groups objects or the string value from relevant SPField&amp;#160; object when retrieving ListItems from a SharePoint List,&amp;#160; and I have found that there are quite a few blog posts on this subject, all with differing code and views.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Having now tested nearly all of them, i have used 2 approaches that have helped me and the are&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font size="2"&gt;Retreiving an SPUser or SPGroup object – perhaps for validation purposes or to gain other information about the user of group &lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font size="2"&gt;Retrieving a User friendly string representation of the User or Group – perhaps for simple display purposes.&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The code below show the retrieval of the SPUser/SPGroup objects&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:362fbe4e-169d-4a81-b2b6-e7326556262c" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;SPList&lt;/span&gt; oList = web.Lists[&lt;span style="color:#a31515"&gt;&amp;quot;ListName&amp;quot;&lt;/span&gt;];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;SPListItemCollection&lt;/span&gt; oListItems = oList.Items;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPListItem&lt;/span&gt; oListItem &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; oListItems)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//Gets a collection of all the User and Group objects from the UserGroup Field&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#2b91af"&gt;SPFieldUserValueCollection&lt;/span&gt; oFieldUserValueCollection =&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUserValueCollection&lt;/span&gt;(web, oListItem[&lt;span style="color:#a31515"&gt;&amp;quot;FieldName&amp;quot;&lt;/span&gt;].ToString());&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//Next, loop through the Values in the Collection&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt; oFieldUserValue &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; oFieldUserValueCollection)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#008000"&gt;//now we need to test if the SPFieldUserValue is a&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#008000"&gt;//User or a  Group, because if we simply assign a user&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#008000"&gt;//we will get a Null Reference Exception if it is a Group&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#008000"&gt;//It is a Group&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (oFieldUserValue.User == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                {&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#008000"&gt;//Create and assign a new SPGroup object by using the&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#008000"&gt;//Lookup value to return a Group from the current Site(SPWeb)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#2b91af"&gt;SPGroup&lt;/span&gt; oGroup = web.Groups.GetByID(oFieldUserValue.LookupId);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                }&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#008000"&gt;//It is a User&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#008000"&gt;//Create and assign a new SPUSer object by using the User&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                    &lt;span style="color:#008000"&gt;//property of the SPFieldUserValue object&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                    &lt;span style="color:#2b91af"&gt;SPUser&lt;/span&gt; oUser = oFieldUserValue.User;&lt;/li&gt; &lt;li&gt;                }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;    &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;and the code below here shows the retrieval if the simple string representation. &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:14dc902c-a842-4b9c-8be8-06f931eb6735" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPList&lt;/span&gt; oList = web.Lists[&lt;span style="color:#a31515"&gt;&amp;quot;ListName&amp;quot;&lt;/span&gt;];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPListItemCollection&lt;/span&gt; oListItems = oList.Items;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;SPListItem&lt;/span&gt; oListItem &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; oListItems)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;SPFieldUserValueCollection&lt;/span&gt; oFieldUserValueCollection&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        = SPFieldUserValueCollection(web, oListItem[&lt;span style="color:#a31515"&gt;&amp;quot;FieldName&amp;quot;&lt;/span&gt;].ToString());&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;     &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt; oFieldUserValue &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; oFieldUserValueCollection)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;//simply retrieve the string value from the SPFieldUserValue object&lt;/span&gt;&lt;/li&gt; &lt;li&gt;         &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; sFieldValue = oFieldUserValue.LookupValue;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;If anyone else has any more thoughts on this please let us know.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-4266586758973028098?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/4266586758973028098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2009/04/fun-with-spfielduservaluecollection.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4266586758973028098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4266586758973028098'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2009/04/fun-with-spfielduservaluecollection.html' title='Fun with SPFieldUserValueCollection'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-3334850023199815209</id><published>2009-02-09T09:17:00.000Z</published><updated>2010-03-16T09:19:02.988Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>SPList.GetItems(SPQuery query) does not search recursively through sub folders in a List by default</title><content type='html'>&lt;p&gt;I developed a custom WebPart which allowed a user to select a list from a site and then execute an advanced search within the selected list.&amp;#160;&amp;#160; The advanced search functionality provided various options to select which fields to filter on, sort and display, using the SPField properties.&lt;/p&gt;  &lt;p&gt;The search execution code was created using the SPList.GetItems(SPQuery query) search function.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Testing was going great until i came across a problem when searching on items in subfolders within a list, the test failed as No items in subfolders were returned.&lt;/p&gt;  &lt;p&gt;I came across this in the SDK which wasn’t obvious to me, so thought I'd ease other people’s pains quickly if it isn’t obvious to you either.&lt;/p&gt;  &lt;p&gt;There is a property called ViewAttributes on the SPQuery object which accepts a string value. The following code shows how to use the property to search recursively through subfolders &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:64e16a59-7000-4432-b2d2-aa6f7a968a62" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;SPList&lt;/span&gt; list = web.Lists[&lt;span style="color:#a31515"&gt;&amp;quot;mylist&amp;quot;&lt;/span&gt;];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;SPQuery&lt;/span&gt; query = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPQuery&lt;/span&gt;();&lt;/li&gt; &lt;li&gt;        query.ViewAttributes = &lt;span style="color:#a31515"&gt;&amp;quot;Scope=&amp;#92;&amp;quot;Recursive&amp;#92;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        query.Query = &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color:#a31515"&gt;&amp;quot;&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name={0} /&amp;gt;&amp;lt;Value Type=&amp;#39;{1}&amp;#39;&amp;gt;{2}&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;myfieldname&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515"&gt;&amp;quot;searchstring&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;SPListItemCollection&lt;/span&gt; itemsReturnedFromQuery = list.GetItems(query);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-3334850023199815209?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/3334850023199815209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2009/02/splistgetitemsspquery-query-does-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3334850023199815209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3334850023199815209'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2009/02/splistgetitemsspquery-query-does-not.html' title='SPList.GetItems(SPQuery query) does not search recursively through sub folders in a List by default'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-8202637285857534148</id><published>2008-09-02T08:40:00.000+01:00</published><updated>2010-03-16T09:37:38.538Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Adding Groups and Users to a SharePoint Site in code</title><content type='html'>&lt;p&gt;There are plenty of blogs around about adding users to groups, but i have found there are not many explaining the end to end code for the creation of a new group in a site, assigning the permissions then adding of users to that group, so here goes.&lt;/p&gt;  &lt;p&gt;Firstly, when you add a group to a site, it is not just the simple case of using the SPGroupCollection add method of the SPWeb object,&amp;#160; you need to follow this up by setting the RoleAssignments and RoleDefinitionsBindings.&lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The code below is using an application page, therefore using the LayoutsPage context to get the SPWeb object using this.Web.&amp;#160;&amp;#160; If you are using this in a web part or other code, then you would wrap this inside a using(SPWeb) or a try catch scoped SPWeb object.&lt;/p&gt;  &lt;p&gt;We start by checking to see if the site is inheriting its permissions and breaking if required. In this example, the existing inherited group permissions are copied across when breaking the inheritance by using the true parameter.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d3ff61e7-5741-4d9c-a8ff-2a887994033b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!web.HasUniqueRoleAssignments)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//use the true parameter to copy the permissions&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;//when breaking inheritance&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            web.BreakRoleInheritance(&lt;span style="color:#0000ff"&gt;true&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt; &lt;!--more--&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Then we need to create the new group by adding in a site owner and default member.&amp;#160; Note: this alone will not create the group in the site, the RoleAssignment and RoleDefinitions need to be added below.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bae54362-3831-4413-ac99-1d5e6948791d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;PeopleEditor&lt;/span&gt; peApproversGroup;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!web.HasUniqueRoleAssignments)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;//use the true parameter to copy the permissions&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//when breaking inheritance&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            web.BreakRoleInheritance(&lt;span style="color:#0000ff"&gt;true&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//Create the group then get a Group Object reference to the created group&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            web.SiteGroups.Add(&lt;span style="color:#a31515"&gt;&amp;quot;Group Name&amp;quot;&lt;/span&gt;, web.CurrentUser, web.CurrentUser, &lt;span style="color:#a31515"&gt;&amp;quot;Site Group Description&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;SPGroup&lt;/span&gt; newGroup = web.SiteGroups[&lt;span style="color:#a31515"&gt;&amp;quot;Group Name&amp;quot;&lt;/span&gt;];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;//Set properties of the group settings&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            newGroup.AllowMembersEditMembership = &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;//Add in the role assignment and definition&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;SPRoleAssignment&lt;/span&gt; roleAssignment = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPRoleAssignment&lt;/span&gt;(newGroup);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            &lt;span style="color:#008000"&gt;//Create object based on Approval role definition&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#2b91af"&gt;SPRoleDefinition&lt;/span&gt; roleDefinition = web.RoleDefinitions[&lt;span style="color:#a31515"&gt;&amp;quot;Approve&amp;quot;&lt;/span&gt;];&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            roleAssignment.RoleDefinitionBindings.Add(roleDefinition);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#008000"&gt;//finally add the role assignment&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            web.RoleAssignments.Add(roleAssignment);&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;PickerEntity&lt;/span&gt; user &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; peApproversGroup.Entities) &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            { &lt;/li&gt; &lt;li&gt;                &lt;span style="color:#2b91af"&gt;SPUser&lt;/span&gt; userToAdd = web.SiteUsers[user.Key]; &lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;                newGroup.AddUser(userToAdd); &lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;            newGroup.Update(); &lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;the group should be created, owner assigned and users added, hope this helps.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-8202637285857534148?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/8202637285857534148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/09/adding-groups-and-users-to-sharepoint.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8202637285857534148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8202637285857534148'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/09/adding-groups-and-users-to-sharepoint.html' title='Adding Groups and Users to a SharePoint Site in code'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-5099721164512736011</id><published>2008-08-07T08:38:00.000+01:00</published><updated>2010-03-16T07:39:24.144Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Create Calendar View filtering on Start Time/End Time</title><content type='html'>&lt;p&gt;There is a really annoying problem within the UI with Calendars whereby when you create a new view on a Calendar list it does not expose the Start Date or End Date to filter on so you cannot create a view for upcoming Events, or events between dates !&lt;/p&gt;  &lt;p&gt;Here is a quick workaround to solve this issue.&lt;/p&gt; &lt;a name='more'&gt;&lt;/a&gt;  &lt;p&gt;Go into the calendar list settings and create a new column, give it a name, then make it a calculated column type and then select the [created] in the Formula box. Select DateTime from the data type and un-tick add to default view.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_XXL39Egrp5Q/S581nwVmmpI/AAAAAAAAACY/4BBp18TlJJc/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_XXL39Egrp5Q/S581ouSugaI/AAAAAAAAACc/sWtKdlQ9hd0/image_thumb.png?imgmax=800" width="244" height="154" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now create a new view, and in the filter section, the new field will appear in the drop down and you can now filter on start date.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_XXL39Egrp5Q/S581p_UiNyI/AAAAAAAAACg/-xzl696Bz7c/s1600-h/image%5B5%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_XXL39Egrp5Q/S581qntyUhI/AAAAAAAAACk/ILe5IRuFft4/image_thumb%5B1%5D.png?imgmax=800" width="244" height="43" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-5099721164512736011?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/5099721164512736011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/08/create-calendar-view-filtering-on-start.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5099721164512736011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5099721164512736011'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/08/create-calendar-view-filtering-on-start.html' title='Create Calendar View filtering on Start Time/End Time'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_XXL39Egrp5Q/S581ouSugaI/AAAAAAAAACc/sWtKdlQ9hd0/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-895676756967139205</id><published>2008-04-24T09:27:00.000+01:00</published><updated>2010-03-11T08:28:48.198Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Retrieving values from SPField objects, not item.ToString()</title><content type='html'>&lt;p&gt;When providing interaction with lists, whether it be via List Event Handlers or Web Parts, it helps to use the casting methods for the fields that you are going to be interacting with when both retrieving and setting values.&lt;/p&gt;  &lt;p&gt;The most widely used scenario where this feature is best used is in Lookup, Choice, URL and User Fields, as the actual value that is stored by accessing the ListItem[&amp;quot;name&amp;quot;].toString() is not always what may be expected.&amp;#160;&amp;#160; Lookup Fields usually store values in this format, Id, #, ;, text.&amp;#160; which can amount to returning &amp;quot;1#;Title&amp;quot;, when you were expecting &amp;quot;Title&amp;quot;, and SPUser fields store a userid followed by the name, e.g. 16#:GavinMorgan&lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Below is a piece of code using some of the more widely used field types which casts the field value retrieved to its native type where more information can be accessed.&lt;/p&gt;  &lt;p&gt;Something else to note here is that we consistently use the internal field.GetByInternalFieldName method to retrieve the field which ensures we always use the internal field name rather than than the title, as this is subject to change. &lt;/p&gt;  &lt;p&gt;This example is from and ItemAdded event handler.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7c2fae45-22b4-436e-a106-50a4daf4f86e" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPListItem&lt;/span&gt; item = properties.ListItem;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//SPUser fields&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPFieldUser&lt;/span&gt; userField = item.Fields.GetFieldByInternalName(&lt;span style="color:#a31515"&gt;&amp;quot;UserInternalFieldName&amp;quot;&lt;/span&gt;) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUser&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt; userFieldValue = userField.GetFieldValue(item[userField.Title].ToString()) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPUser&lt;/span&gt; user = userFieldValue.User;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//Choice Fields&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPFieldChoice&lt;/span&gt; choiceField = item.Fields.GetFieldByInternalName(&lt;span style="color:#a31515"&gt;&amp;quot;ChoiceInternalFieldName&amp;quot;&lt;/span&gt;) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldChoice&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//To access the value&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; selectedChoice = choiceField.GetFieldValueAsText(item[choiceField.Title]);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//To access list of choices in field&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; choice &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; choiceField.Choices)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (choice == &lt;span style="color:#a31515"&gt;&amp;quot;choice 1&amp;quot;&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    { &lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;//do something with choices&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#008000"&gt;//To add a new choice&lt;/span&gt;&lt;/li&gt; &lt;li&gt;choiceField.Choices.Add(&lt;span style="color:#a31515"&gt;&amp;quot;New Choice&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;choiceField.Update();&lt;/li&gt; &lt;li&gt;&lt;span style="color:#008000"&gt;//URL Fields&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPFieldUrl&lt;/span&gt; urlField = item.Fields.GetFieldByInternalName(&lt;span style="color:#a31515"&gt;&amp;quot;URLInternalFieldName&amp;quot;&lt;/span&gt;) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUrl&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPFieldUrlValue&lt;/span&gt; urlFieldValue = urlField.GetFieldValue(item[urlField.Title].ToString()) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUrlValue&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; url = urlFieldValue.Url;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; desc = urlFieldValue.Description;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;I will try to add more Field Types as i use them. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-895676756967139205?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/895676756967139205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/04/retrieving-values-from-spfield-objects.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/895676756967139205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/895676756967139205'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/04/retrieving-values-from-spfield-objects.html' title='Retrieving values from SPField objects, not item.ToString()'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-3573268748433770041</id><published>2008-03-20T08:07:00.000Z</published><updated>2010-03-11T08:09:36.006Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Accessing BeforeProperties and AfterProperties on List Item Event Handler</title><content type='html'>&lt;p&gt;I have had numerous occasions during event handler development where i have needed to access the BeforeProperties and AfterProperties of a list item which is being used to compare or retrieve values.&amp;#160; &lt;/p&gt;  &lt;p&gt;You can attack this by either accessing the property directly or looping through the HashTable collection of properties using the Key/Value pairing.&amp;#160; The key thing to note here is that it is solely meta data you are returning, and there is no opportunity to cast to an SPField type.&lt;/p&gt;  &lt;p&gt;Accessing Property Directly&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cc7644bc-391c-4bf6-899c-17f00acc1994" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; valueOfBeforeField = properties.BeforeProperties[&lt;span style="color:#a31515"&gt;&amp;quot;fieldname&amp;quot;&lt;/span&gt;].ToString();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; valueOfAfterField = properties.AfterProperties[&lt;span style="color:#a31515"&gt;&amp;quot;fieldname&amp;quot;&lt;/span&gt;].ToString();&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Looping through property Collection&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dff26817-185b-4701-8b5b-c9a9b88d1b4b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;DictionaryEntry&lt;/span&gt; de &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; properties.AfterProperties)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt;(de.Key.ToString() == &lt;span style="color:#a31515"&gt;&amp;quot;fieldname&amp;quot;&lt;/span&gt;)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; valueOfField1 = de.Value.ToString();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-3573268748433770041?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/3573268748433770041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/03/accessing-beforeproperties-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3573268748433770041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/3573268748433770041'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/03/accessing-beforeproperties-and.html' title='Accessing BeforeProperties and AfterProperties on List Item Event Handler'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-2766778467480400590</id><published>2008-02-19T17:30:00.000Z</published><updated>2010-03-10T17:31:34.454Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Retrieving an SPUser object from an SPListItem</title><content type='html'>&lt;p&gt;Whilst coding a Timer Job I came across a requirement to extract the user's email address from a User Type column in a SharePoint list item. I must admit, naively I thought it would be as simple as casting the ListItem[&amp;quot;user&amp;quot;] as SPUser, but to my surprise this produced a lovely error.&lt;/p&gt;  &lt;p&gt;Finally after dredging through the SDK and other blogs/forums and my determination not to have to use the SPSite.AllUsers, I cam up with this solution which seems to work nicely&lt;/p&gt;  &lt;p&gt;Simple and effective.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1827a20e-dcd0-4054-828b-607e99e2b207" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPFieldUser&lt;/span&gt; userField = listItem.Fields.GetFieldByInternalName(&lt;span style="color:#a31515"&gt;&amp;quot;InternalFieldName&amp;quot;&lt;/span&gt;) &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUser&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt; userFieldValues = listItem[userField.Title] &lt;span style="color:#0000ff"&gt;as&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPFieldUserValue&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPUser&lt;/span&gt; userFromListItem = userFieldValues.User;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; userEmailAddress = userFromListItem.Email;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-2766778467480400590?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/2766778467480400590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/02/retrieving-spuser-object-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/2766778467480400590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/2766778467480400590'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/02/retrieving-spuser-object-from.html' title='Retrieving an SPUser object from an SPListItem'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-8865761933991432564</id><published>2008-02-01T15:26:00.000Z</published><updated>2010-03-10T17:34:18.302Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>CAML Queries with DateTime values</title><content type='html'>&lt;p&gt;I came across an interesting problem whilst using the SPQuery object, CAML and DateTime Fields (at the time I was using them in a Timer Job, but it is not specific to that)&lt;/p&gt;  &lt;p&gt;Firstly I found that if you have any problems with the CAML query, &lt;/p&gt;  &lt;blockquote&gt;   &lt;ol&gt;     &lt;li&gt;the first you know about it is when you try to use the SPList object or SPLIstItemCollection objects on which you based the query. &lt;/li&gt;      &lt;li&gt;The only error message you are likely to get is &amp;quot;Cannot complete this action, please retry&amp;quot; &lt;/li&gt;   &lt;/ol&gt; &lt;/blockquote&gt;  &lt;p&gt;One bit that they fail to tell you is that if you are using a DateTime in a CAML query and you are comparing lets say today's date against a Date field in your list, you need to include the property &amp;quot;IncludeTimeValue&amp;quot; and set it to TRUE on the &amp;quot;&amp;lt;Value&amp;gt;&amp;quot; element, so the XML looks like this &lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 2px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 600px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  1: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;FieldRef&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;MyDate&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  2: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Value&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;DateTime&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;IncludeTimeValue&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;&amp;quot;TRUE&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  3: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Today&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #ddeceb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  4: &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you don’t use it then you will get the &amp;quot;Cannot complete this action&amp;quot; error when using the SPListItemCollection object.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Additionally, you need to bear in mind the following when using CAML from your C# code.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;You need the internal names of your fields when using them in the CAML Code. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;When using a both a string/choice/lookup field and&amp;#160; a DateTime field in your query using the AND clause, you need 2 AND clauses in there. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://blog.gemsolution.co.uk/__oneclick_uploads/2008/02/image1.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-8865761933991432564?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/8865761933991432564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2010/02/caml-queries-with-datetime-values.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8865761933991432564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8865761933991432564'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2010/02/caml-queries-with-datetime-values.html' title='CAML Queries with DateTime values'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-8598598253090173755</id><published>2008-01-04T15:22:00.000Z</published><updated>2010-03-10T15:23:41.292Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Customisation'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Calculated Column using [Today]</title><content type='html'>&lt;p&gt;SharePoint has many niggling frustrations where you think functionality should be readily available, only to find that for some reason the Microsoft team have decided to make life a little harder and not include it.&amp;#160; So more and more we find ourselves having to find yet another work around..&lt;/p&gt;  &lt;p&gt;Here, SharePoint complains about including the [Today] field in a Calculated column. Thankfully there is a work around, and it seems as though we are tricking SharePoint with this one.&lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create a new column in your list and call it &amp;quot;Today&amp;quot;, for now just use a single line text and leave all defaults, click ok to save. &lt;/li&gt;    &lt;li&gt;Now create your calculated column, and in your calculation, you can select the column created above, named &amp;quot;Today&amp;quot;.&amp;#160; so you may have a calculation which looks like the following.&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;&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;&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; =DATEDIF([Created], [Today], &amp;quot;d&amp;quot;)&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;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; which will calculate the number of days between the created date and the current date.&amp;#160; Click OK to save the column. &lt;/li&gt;    &lt;li&gt;Now delete the column you created in section 1.&amp;#160; Your calculation should now work. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You need to bear in mind that if you change the calculation and you are still using [Today] in the calculation, you will have to recreate the &amp;quot;Today&amp;quot; column as in step 1 as SharePoint will attempt to re-parse the calculation and complain about basing it on a [Today] field.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-8598598253090173755?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/8598598253090173755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2008/01/calculated-column-using-today.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8598598253090173755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/8598598253090173755'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2008/01/calculated-column-using-today.html' title='Calculated Column using [Today]'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-4085319797933374328</id><published>2007-06-15T23:43:00.000+01:00</published><updated>2010-03-09T22:43:58.569Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint 2007'/><title type='text'>Disposing of SPSite and SPWeb Objects</title><content type='html'>&lt;p&gt;Wherever you use the SPWeb and SPSite objects, you must always dispose them after use. You can do this by either explicitly disposing of the by calling the dispose method, or encasing them in a &amp;quot;using&amp;quot; statement, &amp;quot;scope&amp;quot;.&amp;#160; .If you do not dispose of the objects then memory can quickly be consumed and eventually, dependent on the scale of your architecture, your environment will grind to a halt.&lt;/p&gt;  &lt;p&gt;So how do we Dispose or Scope ?&amp;#160; Bear in mind that both of these methods are as efficient as each other.&lt;/p&gt;  &lt;p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Dispose SPSite and SPWeb&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;There are 2 scenarios where you must be disposing of the SPSite and SPWeb objects. The first is a general assignment scenario, which is disposing of the SPSite and SPWeb objects directly. The second is the one that is usually missed and more critical in causing memory leaks which involves the use of the SPWeb object within a Foreach loop.&amp;#160; both are documented below.&lt;/p&gt;  &lt;p&gt;General dispose after use, I have been also enclosed this in a try, catch, finally statement to enable greater exception handling.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4e6fd169-ff17-495d-8afe-fe36e837d037" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#008000"&gt;//other code here&lt;/span&gt;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;finally&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    web.Dispose();&lt;/li&gt; &lt;li&gt;    site.Dispose();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Disposing of SPWeb in foreach loop.&amp;#160; the subWeb object in the code below is explicitly disposed of.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6a210052-bf32-4e90-b5e2-b4f4e3bdbccf" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#2b91af"&gt;SPWebCollection&lt;/span&gt; allWebs = site.AllWebs;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; allWebs)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{ &lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;//other code here&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    web.Dispose();&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;site.Dispose();&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Scope SPSite and SPWeb&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Within your assignment of the SPSite and SPWeb objects, encase them in a using statement. This will dispose of the objects once the scope of the code runs outside the using scope.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8ca90a1f-09f4-485f-8f11-e0b0db59dede" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px; white-space: nowrap"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt; site = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://mysite.com/sitecollection&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;using&lt;/span&gt; (&lt;span style="color:#2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb(&lt;span style="color:#a31515"&gt;&amp;quot;mysitename&amp;quot;&lt;/span&gt;))&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    { &lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;//other code here&lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;if you use a foreach loop within the using statement, the subwebs will still have to be disposed of explicitly.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-4085319797933374328?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/4085319797933374328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2007/06/disposing-of-spsite-and-spweb-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4085319797933374328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/4085319797933374328'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2007/06/disposing-of-spsite-and-spweb-objects.html' title='Disposing of SPSite and SPWeb Objects'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6188351627206500991.post-5612884499383577797</id><published>2007-06-01T10:13:00.000+01:00</published><updated>2010-03-09T09:14:48.583Z</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Welcome</title><content type='html'>&lt;p&gt;Welcome to the GEMSolution Blog Site. &lt;/p&gt;  &lt;p&gt;This Blog will be geared towards the SharePoint development and customisation world, and the problems and fun that this brings to people's lives. &lt;/p&gt;  &lt;p&gt;Please feel free to register and add posts to this blog site with your problems, questions and comments and hopefully this can build up to be another source of information for people venturing into the world of SharePoint. &lt;/p&gt;  &lt;p&gt;happy SharePoint'ing&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6188351627206500991-5612884499383577797?l=gemsolution.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gemsolution.blogspot.com/feeds/5612884499383577797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gemsolution.blogspot.com/2007/06/welcome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5612884499383577797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6188351627206500991/posts/default/5612884499383577797'/><link rel='alternate' type='text/html' href='http://gemsolution.blogspot.com/2007/06/welcome.html' title='Welcome'/><author><name>Gavin Morgan</name><uri>http://www.blogger.com/profile/15472100376136776624</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
