<?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/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;CUQGQnkyfSp7ImA9WhRTEk4.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666</id><updated>2011-11-02T04:28:43.795-07:00</updated><category term='deploy worfklow'/><category term='sharepoint update delete item list'/><category term='sharepoint SPSecurity RunWithElevatedPrivileges grant full permission'/><category term='sharepoint server error message IE enable scripts'/><category term='workflow reset time service'/><category term='sharepoint SPFieldLookup SPFieldLookupvalue SPFieldLookupValueCollection lookup'/><category term='onTaskCreated activity do not fire'/><category term='Web application could not be found'/><category term='LCDI  Locale IDs'/><category term='SharePoint groups user'/><category term='sharePoint LINQ System.NullReferenceException'/><category term='workflow history list'/><category term='get SPUser user person group field'/><category term='CreateHistoryEvent method onTaskCreated activity event receiver'/><category term='stsadm commands wsp sharePoint solution feature install deploy activate deactivate retract delete'/><category term='blank empty page site settings'/><category term='web template name'/><category term='sharepoint update item disable event firing'/><category term='arguments not valid site template create'/><category term='ListViewByQuery Control'/><category term='sharepoint check field value'/><category term='SharePoint current user permission level greater or equal role'/><category term='get SPUser  SPGroup Person Group field'/><title>MS SharePoint and other stuffs around</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;CUQGQnY_cCp7ImA9WhRTEk4.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-4072852934683932904</id><published>2011-11-02T01:32:00.000-07:00</published><updated>2011-11-02T04:28:43.848-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-11-02T04:28:43.848-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='get SPUser  SPGroup Person Group field'/><title>How to get SPUser or SPGroup from Person or Group field</title><content type='html'>Ok, here is the thing - you have person or group field in SharePoint list and you want to programmatically get the user or person.&lt;br /&gt;
&lt;br /&gt;
This code snippet gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field:&lt;br /&gt;
//get SPUser&lt;br /&gt;
&lt;i&gt;SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPUser user = userFieldValue.User;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;//Multiple choices are allowed&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;foreach (SPFieldUserValue userFieldValue in userFieldValueCollection)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; Console.WriteLine(" &amp;nbsp; &amp;nbsp; " + userFieldValue.User.LoginName);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
And when group is allowed &amp;nbsp;you can use this code(In this part I'm not quite sure about solution. I wrote it, It's working, but maybe there is better approach so if you know better do not hesitated to comment it :) ):&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;//Group or User are allowed&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;//Tries to get SPUser&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;if (&lt;/i&gt;&lt;i&gt;userFieldValue.User != null&lt;/i&gt;&lt;i&gt;)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;i&gt;SPUser user = userFieldValue.User;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;//if the field contain group&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;else&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;i&gt;SPGroup group = web.SiteGroups.GetByID(userFieldValue.LookupId);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
Happy coding ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-4072852934683932904?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/4072852934683932904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/11/how-to-get-spuser-or-spgroup-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4072852934683932904?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4072852934683932904?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/11/how-to-get-spuser-or-spgroup-from.html' title='How to get SPUser or SPGroup from Person or Group field'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkIDRnsyfip7ImA9WhRTEUg.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-1651142432401154854</id><published>2011-11-01T05:29:00.000-07:00</published><updated>2011-11-01T05:29:37.596-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-11-01T05:29:37.596-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='ListViewByQuery Control'/><title>ListViewByQuery Control</title><content type='html'>Recently I needed to develop some cross site list view and this two links really helped me out of it.&lt;br /&gt;
Creating list view webpart:&lt;br /&gt;
&lt;a href="http://brandingsharepointsites.wordpress.com/2011/07/29/display-sharepoint-list-view-or-document-library-view-from-different-site-collection/"&gt;http://brandingsharepointsites.wordpress.com/2011/07/29/display-sharepoint-list-view-or-document-library-view-from-different-site-collection/&lt;/a&gt;&lt;br /&gt;
Sorting, filtering and grouping functions:&lt;br /&gt;
&lt;a href="http://karinebosch.wordpress.com/sharepoint-controls/the-listviewbyquery-control/"&gt;http://karinebosch.wordpress.com/sharepoint-controls/the-listviewbyquery-control/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Thanks a lot :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-1651142432401154854?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/1651142432401154854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/11/listviewbyquery-control.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/1651142432401154854?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/1651142432401154854?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/11/listviewbyquery-control.html' title='ListViewByQuery Control'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkYHQXk-eSp7ImA9WhRTEUg.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-437430366117388064</id><published>2011-11-01T05:22:00.000-07:00</published><updated>2011-11-01T05:22:10.751-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-11-01T05:22:10.751-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='LCDI  Locale IDs'/><title>LCDI - Locale IDs Assigned by Microsoft</title><content type='html'>This site just contains list of Windows locale IDs:&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/goglobal/bb964664"&gt;http://msdn.microsoft.com/en-us/goglobal/bb964664&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-437430366117388064?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/437430366117388064/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/11/lcdi-locale-ids-assigned-by-microsoft.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/437430366117388064?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/437430366117388064?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/11/lcdi-locale-ids-assigned-by-microsoft.html' title='LCDI - Locale IDs Assigned by Microsoft'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;D0EARXw7fSp7ImA9WhRTEUk.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-2002840489925763919</id><published>2011-11-01T04:07:00.000-07:00</published><updated>2011-11-01T04:07:24.205-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-11-01T04:07:24.205-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='arguments not valid site template create'/><title>File or arguments not valid for site template or how to create site from web template</title><content type='html'>This short code snippet creates a new SharePoint site from site template:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;using (SPSite site = new SPSite("http://spserver/"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWeb web = site.OpenWeb();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWebTemplateCollection Templates = site.GetCustomWebTemplates(web.Language);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWebTemplate siteTemplate = Templates["mySiteTemplate.stp"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Checks whether site requested is exist or not&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (web.Webs["test"].Exists)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; web.Webs.Delete("test");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Creates a new site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; web.Webs.Add("test", "This is test site", "", Convert.ToUInt32(web.Language), siteTemplate, true, false);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
If you would receive this error message:&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;b&gt;File or arguments not valid for site template "someTemplate"&lt;/b&gt;&lt;br /&gt;
You can check two things to fix this error:&lt;br /&gt;
The first one is to use correct function to get web templates from your site. If you would use &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.getwebtemplates.aspx"&gt;GetWebTemplates(unit LCID)&lt;/a&gt;&amp;nbsp;function you will get default site templates and if you need to use site template which you were created you should use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.getcustomwebtemplates.aspx"&gt;GetCustomWebTemplates(unit LCID)&lt;/a&gt;.&lt;br /&gt;
The second is to use correct site template name. Check this &lt;a href="http://david-row.blogspot.com/2011/11/get-correct-sharepoint-web-template.html"&gt;link &lt;/a&gt;to find out how to get the proper site template name.&lt;br /&gt;
&lt;br /&gt;
Hope it helps ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-2002840489925763919?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/2002840489925763919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/11/file-or-arguments-not-valid-for-site.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/2002840489925763919?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/2002840489925763919?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/11/file-or-arguments-not-valid-for-site.html' title='File or arguments not valid for site template or how to create site from web template'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DkQGR3k-cSp7ImA9WhRTEUk.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-5355694704335832063</id><published>2011-11-01T03:45:00.000-07:00</published><updated>2011-11-01T03:45:26.759-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-11-01T03:45:26.759-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='web template name'/><title>Get correct SharePoint web template name</title><content type='html'>You can use this URL, if you would need to find out the name of your web template:&lt;br /&gt;
&lt;b&gt;http://[server]/_layouts/templatepick.aspx&lt;/b&gt;&lt;br /&gt;
Just the [server] replace with your server name. Then view source code and the name you are looking for is value of &lt;i&gt;"value"&lt;/i&gt; attribute inside&amp;nbsp;&lt;i&gt;"option"&lt;/i&gt; tag in the list box.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-5355694704335832063?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/5355694704335832063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/11/get-correct-sharepoint-web-template.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5355694704335832063?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5355694704335832063?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/11/get-correct-sharepoint-web-template.html' title='Get correct SharePoint web template name'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkANRnw4eCp7ImA9WhdVFkU.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-6479017154562707875</id><published>2011-09-21T08:11:00.000-07:00</published><updated>2011-09-22T01:39:57.230-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-22T01:39:57.230-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='onTaskCreated activity do not fire'/><title>onTaskCreated activity do not fire</title><content type='html'>Recently I created parallel task approval workflow and I needed to use the onTaskCreated activity. Till that my workflow worked fine and since I added this activity to the project the workflow stopped working properly. I search for the solution on the Internet and it turns out that this is Microsoft bug and it seems to be permanent. More about it you can read here:&amp;nbsp;&lt;a href="http://support.microsoft.com/kb/970548"&gt;http://support.microsoft.com/kb/970548&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There are two ways how to achieve the same functionality.&lt;br /&gt;
First one is to create event receiver in the task list. Second one is to add Delay activity after CreateTask activity and then perform some code(Delay activity ensure that task will be created and you can work with them then).&lt;br /&gt;
&lt;br /&gt;
I used event receiver to substitute the onTaskCreated activity. How I did it you can look here on my blog:&amp;nbsp;&lt;a href="http://david-row.blogspot.com/2011/09/how-to-create-workflow-history-event.html"&gt;http://david-row.blogspot.com/2011/09/how-to-create-workflow-history-event.html&lt;/a&gt;&lt;br /&gt;
Anyway even that Microsoft offers workaround, it will cause more work than just drag and drop activity to your workflow. Also you have divided one project to the two and sometime it can be really bothering to make some changes in them.&lt;br /&gt;
&lt;br /&gt;
I also tried second way with Delay activity but it doesn't seems to be good solution. As I wrote above I was creating parallel task approval process and problem was that somebody could approve task when Delay activity was still running. This cause that approval this task was not registered by workflow. So if I would be sure that nobody would approve task for example in first hour I could use this solution. Even you can set timer job of the workflow on 1 minute it still doesn't seems to be good solution to me.&lt;br /&gt;
&lt;br /&gt;
This is just my opinion and you can also read more on this blog:&amp;nbsp;&lt;a href="http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=69"&gt;http://www.elumenotion.com/Blog/Lists/Posts/Post.aspx?ID=69&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Ok then, I hope this can help somebody to choose which way to substitute onTaskCreated activity. Both solutions have their pros and cons... Maybe Microsoft will solve some bugs in next version of SharePoint :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-6479017154562707875?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/6479017154562707875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/ontaskcreated-activity-do-not-fire.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6479017154562707875?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6479017154562707875?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/ontaskcreated-activity-do-not-fire.html' title='onTaskCreated activity do not fire'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEYASHY_eSp7ImA9WhdVFkw.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-8577939008639348707</id><published>2011-09-21T06:35:00.000-07:00</published><updated>2011-09-21T06:35:49.841-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-21T06:35:49.841-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='deploy worfklow'/><title>How to deploy SharePoint 2010 workflow</title><content type='html'>Once you are done with testing your workflow on test server you would probably need to deploy this workflow to bring it alive :)&lt;br /&gt;
&lt;br /&gt;
First easy way (which wasn't work for me) is to create wsp package:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;After you built&amp;nbsp;your project, you can right click on the project in Visual Studio and choose Package option&lt;/li&gt;
&lt;li&gt;Find wsp file in debug folder of your project (usually C:\Users\user1\Documents\Visual Studio 2010\Projects\MyWorflow\MyWorkflow\bin\Debug). If you want to you can rename MyWorflow.wsp to MyWorkflow.cab and look what VS did for you :)&lt;/li&gt;
&lt;li&gt;Upload a new solution - Open solution gallery in browser (Site Actions-&amp;gt;Site Settings-&amp;gt;Under Galleries section choose Solutions) and upload wsp file you have just created. Do not forget activate solution.&lt;/li&gt;
&lt;li&gt;By now you should see a new feature in Site collection features, but before adding workflow to your list you should check if a new assembly is installed otherwise workflow would be codeless :). You can find it here C:\Windows\assembly\. If the assembly file contain your dll everything is right. If there is not and if you are administrator you can drag and drop dll into assembly file or use &lt;a href="http://msdn.microsoft.com/en-us/library/ex0ss12c(v=vs.80).aspx"&gt;gacutil &lt;/a&gt;to install dll.&lt;/li&gt;
&lt;li&gt;Now you can add a new workflow to your list and you should see your workflow name in "Select a workflow template" box. In this point this technique stops work for me&lt;/li&gt;
&lt;/ul&gt;Second way which saves me is little bit more complicated but not too much :)&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;If you don't know anything about features in SharePoint you should probably read this first:&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/ms460318.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms460318.aspx&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/ms475601.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms475601.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;To make it easier I ran workflow in debug mode on test server, then I have copied whole feature folder. Usually you can find feature folder here:&amp;nbsp;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES but&amp;nbsp;of-course&amp;nbsp;depend on your&amp;nbsp;installation.&lt;/li&gt;
&lt;li&gt;I have pasted this folder into the same location on server where I wanted to deploy the workflow&lt;/li&gt;
&lt;li&gt;Then I have installed assembly of workflow using same way as I described above&lt;/li&gt;
&lt;li&gt;I have installed and activated a new feature using&amp;nbsp;&lt;a href="http://technet.microsoft.com/en-us/library/cc261956(office.12).aspx"&gt;stsadm&lt;/a&gt;&amp;nbsp;command tool. Command to install and activate feature you can find on my blog here:&amp;nbsp;&lt;a href="http://david-row.blogspot.com/2011/07/stsadm-commands-to-install-wsp-file.html"&gt;http://david-row.blogspot.com/2011/07/stsadm-commands-to-install-wsp-file.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;After that I was able to add a new workflow to my list&lt;/li&gt;
&lt;/ul&gt;Till now I don't know why the first method didn't work, but I have tried it with event receiver and it worked fine. Anyway is nice to know that SharePoint offers more than just one way to deploy solutions.&lt;br /&gt;
If anyone has experience with this do not hesitate to comment it ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-8577939008639348707?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/8577939008639348707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/how-to-deploy-sharepoint-2010-workflow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/8577939008639348707?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/8577939008639348707?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/how-to-deploy-sharepoint-2010-workflow.html' title='How to deploy SharePoint 2010 workflow'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CkMNQnk5fSp7ImA9WhdVFk0.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-1616349302158886156</id><published>2011-09-21T03:21:00.000-07:00</published><updated>2011-09-21T03:21:33.725-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-21T03:21:33.725-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='workflow history list'/><title>View  workflow history list</title><content type='html'>Maybe you would need to view or work with data from your workflow history and for this is useful to know where all logs are stored&amp;nbsp;in SharePoint. Because this list is hidden you need to use way around. Each site where runs some workflow has own history log list.&lt;br /&gt;
The URL can look like this:&amp;nbsp;http://[spServer]/[spSite]/Lists/Workflow%20History/[ViewName].aspx&lt;br /&gt;
&lt;br /&gt;
Default view namey is AllItems. This view probably doesn't match your expectation because contain some columns with GUIDs and shows all items of each workflow.&lt;br /&gt;
I needed to view just this columns - &amp;nbsp;User ID, Date Occurred and Description so I have created a new view and used this view in URL.&lt;br /&gt;
This will provide you user friendly view but still doesn't solve problem with all items because usually you need to view just some particular items. Here is the method I have used in workflow to get link which shows you just particular item.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;summary&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// Returns workflow history list URL and replace space with '%20'&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;returns&amp;gt;Returns workflow history list URL&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; private string getWorkflowHistoryListUrl()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string url = this.spRootSite + this.workflowProperties.HistoryListUrl.Replace(" ", "%20");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Specify the view&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url += "/UserView.aspx?";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Column which contain ID of particular list item where workflow runs&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url += "FilterField1=Item&amp;amp;";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Item ID&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url += "FilterValue1=" + this.workflowProperties.ItemId;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return url;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
If you use better solution, please comment it ;)&lt;br /&gt;
At the end, do not forget that SharePoint deletes all records of canceled or completed workflows which are older than 60 days. If you would want to remain history list you can use this link for further information:&amp;nbsp;&lt;a href="http://technet.microsoft.com/en-us/library/ee662522.aspx"&gt;http://technet.microsoft.com/en-us/library/ee662522.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Hope it helps somebody...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-1616349302158886156?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/1616349302158886156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/view-workflow-history-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/1616349302158886156?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/1616349302158886156?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/view-workflow-history-list.html' title='View  workflow history list'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DEIMQX89eCp7ImA9WhdVFUQ.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-9057252022712772687</id><published>2011-09-21T02:15:00.000-07:00</published><updated>2011-09-21T02:16:20.160-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-21T02:16:20.160-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='CreateHistoryEvent method onTaskCreated activity event receiver'/><title>How to create workflow history event</title><content type='html'>When you need to create a new workflow history event you can use one of these two functions&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms442272.aspx"&gt;CreateHistoryEvent(Int32, Object, SPMember, String, String, String)&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms443973.aspx"&gt;CreateHistoryEvent(SPWeb, Guid, Int32, SPMember, TimeSpan, String, String, String)&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
second one is static so do not misinterpret parameters as I did first time :)&lt;br /&gt;
&lt;br /&gt;
To create history event via function is helpful when you don't work directly with workflow code and so you can't use logToHistoryList activity.&lt;br /&gt;
This can be helpful when onTaskCreated activity doesn't work for example.(It can happen when you use replicator activity to creates tasks.) Microsoft describe solution for this here:&amp;nbsp;&lt;a href="http://support.microsoft.com/kb/970548"&gt;http://support.microsoft.com/kb/970548&lt;/a&gt;&amp;nbsp;Obviously it is bug but it wasn't solve yet.&lt;br /&gt;
In brief: You need to create event receiver for Task list and then you can create workflow history event for example.&lt;br /&gt;
Here is one way how to achieve this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;using (SPSite site = new SPSite("http://sharepointserver/"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Gets list where workflow runs&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList workflowList = web.Lists["workflowList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Loop through item in workflow list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem item in workflowList.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Find out which workflow item creates the task&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (properties.ListItem["Workflow Item ID"].ToString() == item["ID"].ToString())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Log to the history list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Use the foreach loop if there is just one workflow&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //otherwise you should find correct workflow&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPWorkflow wf in item.Workflows)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; wf.CreateHistoryEvent((int)SPWorkflowHistoryEventType.TaskCreated, 0, wf.AuthorUser, "", "Task was succesfully assigned to.", "");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Work is done. Get out from loops&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch (Exception ex)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Some exception handling&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Ok this is all. As I describe above this is just one of the ways how to write this code, so if you know better one do not hesitate to comment it. About bug with onTaskCreate activity I want to post later so this post is more focused on useful using of CreateHistoryEvent method.&lt;br /&gt;
Happy coding :)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-9057252022712772687?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/9057252022712772687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/how-to-create-workflow-history-event.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/9057252022712772687?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/9057252022712772687?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/how-to-create-workflow-history-event.html' title='How to create workflow history event'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkICRnw_fyp7ImA9WhdVFU8.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-4660585947062170130</id><published>2011-09-20T07:22:00.000-07:00</published><updated>2011-09-20T07:22:47.247-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-20T07:22:47.247-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='get SPUser user person group field'/><title>Get SPUser from Person/Group field</title><content type='html'>This code snippet could help you easily gets the User from Person/Group field in SharePoint list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;SPFieldUserValue userField = (SPFieldUserValue)list.Fields["Assigned To"].GetFieldValue(item["Assigned To"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;SPUser user=&amp;nbsp;userField.User;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
Happy coding ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-4660585947062170130?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/4660585947062170130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/get-spuser-from-persongroup-field.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4660585947062170130?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4660585947062170130?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/get-spuser-from-persongroup-field.html' title='Get SPUser from Person/Group field'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUUCSXkyeyp7ImA9WhdVFU8.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-5202442624326285407</id><published>2011-09-20T07:01:00.000-07:00</published><updated>2011-09-20T07:01:08.793-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-20T07:01:08.793-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='blank empty page site settings'/><title>Blank page - SP2010 Site settings</title><content type='html'>Few weeks ago I needed to develop something on the new SharePoint server. Everything looked fine and there was not any problem till I needed to open Site settings in browser. When I was trying to open it the blank page was viewed. There was not any content at all or error message and it looked to me really strange.&lt;br /&gt;
To solve this problem was quite simple. You should check Alternate Access Mapping in Central Administration and if the server name in your URL is not there you should rewrite it or add a new record to the Alternate Access Mapping. This was exactly my problem 'cause I used IP address in URL (like this http://10.251.27.150/SitePages/Home.aspx) and in the Alternate Access Mapping was just record about server name (like this http://newSPServer).&lt;br /&gt;
I am not SharePoint administrator but this could help somebody, I hope ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-5202442624326285407?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/5202442624326285407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/blank-page-sp2010-site-settings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5202442624326285407?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5202442624326285407?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/blank-page-sp2010-site-settings.html' title='Blank page - SP2010 Site settings'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;D0QNQns7cSp7ImA9WhdVFU8.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-4595363698319835801</id><published>2011-09-20T06:29:00.000-07:00</published><updated>2011-09-20T06:29:53.509-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-09-20T06:29:53.509-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='Web application could not be found'/><title>The Web application at http://server/ could not be found. - Error</title><content type='html'>When you create SharePoint console application or create webParts, you usually need to use SPSite class to operate with list, web, etc. Recently I got this exception message and it cause me a small headache to fix it.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;The Web application at http://sharepointserver/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Even this message looks like it shows you where the real problem is, the source can be actually somewhere else. I collected some information how to fix it so you can check it first before you will start search somewhere &amp;nbsp;;)&lt;br /&gt;
&lt;br /&gt;
1) Try to check if you typed correct server name as message&amp;nbsp;recommend&amp;nbsp;to you.&lt;br /&gt;
&lt;br /&gt;
2) Check if you have set correctly your platform target in project properties&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Open project properties (Right click on project -&amp;gt; Properties) -&amp;gt; In the left pane select Build folder -&amp;gt; and there select the Platform target to x64&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
3) Problem can be with alternate access mapping&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;(If you use SP2010) Open Central Administration -&amp;gt; Application Management -&amp;gt; Under Web Application section click on the Configure alternate access mapping&lt;/li&gt;
&lt;li&gt;Check if Internal URL contain the URL you have used in your source code otherwise you can create a new record&lt;/li&gt;
&lt;/ul&gt;4) Check if the user is farm server administrator&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Open Central Administration -&amp;gt; Security -&amp;gt; Manage the farm administrators group -&amp;gt; And add the user there&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
If those steps would not help you can also check these points if the user&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;has Read and Write permissions on the content database&lt;/li&gt;
&lt;li&gt;is site collection administrator&lt;/li&gt;
&lt;li&gt;is in WSS_ADMIN_WPG group on the server&lt;/li&gt;
&lt;/ul&gt;If the problem remain try to log as administrator and run your application. If it is work, probably the problem is with the user permission.&lt;br /&gt;
&lt;br /&gt;
Ok then, this is all I found about this exception and I hope it can help somebody as it helps me :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-4595363698319835801?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/4595363698319835801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/09/web-application-at-httpserver-could-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4595363698319835801?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4595363698319835801?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/09/web-application-at-httpserver-could-not.html' title='The Web application at http://server/ could not be found. - Error'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CUUEQns8eSp7ImA9WhdQFUU.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-3372548027662143359</id><published>2011-08-17T05:13:00.000-07:00</published><updated>2011-08-17T05:13:23.571-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-17T05:13:23.571-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint server error message IE enable scripts'/><title>IE throw this error message: You may be trying to access this site from a secured browser on the server. Please enable scripts and reload this page.</title><content type='html'>After you install Windows Server 2008 and SharePoint server 2010 your Internet Explorer (in my case it was IE8) may throw this error message after you try to open SharePoint site in it. Solution is quite easy, just go to the&amp;nbsp;&lt;b&gt;Start -&amp;gt; Administrative Tools -&amp;gt; Server Manager -&amp;gt; on the right side click on the Configure IE ESC -&amp;gt; Choose Off for Administrators and submit it&lt;/b&gt;&lt;br /&gt;
That should be all you need to do.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-3372548027662143359?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/3372548027662143359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/ie-throw-this-error-message-you-may-be.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/3372548027662143359?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/3372548027662143359?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/ie-throw-this-error-message-you-may-be.html' title='IE throw this error message: You may be trying to access this site from a secured browser on the server. Please enable scripts and reload this page.'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CUUHQXYzeyp7ImA9WhdQEEg.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-5889889815209596439</id><published>2011-08-11T02:00:00.000-07:00</published><updated>2011-08-11T02:00:30.883-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-11T02:00:30.883-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint SPSecurity RunWithElevatedPrivileges grant full permission'/><title>How to programmatically ensure full permission to the list, document etc.</title><content type='html'>Sometimes we need to grant full permission to the list, library etc. even user has not access to that list. Let's imagine this situation. You have Site A with list "Orders" on it and also you have site B. On site B is web part which shows data in "Orders" list, but if user has no-permission to the Site A or "Orders" list you can't use code below because you wold get an error that user has no-permission to the site:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SPSite site = new SPSite("http://spsite/siteA");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWeb web = site.OpenWeb();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["Orders"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPItem i in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; someTable.Add(i["Name"].toString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Solution for this is more than simple. All you have to do is use&amp;nbsp;SPSecurity class and&amp;nbsp;RunWithElevatedPrivileges method. This method will grant you full control rights. Using this method and code above would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPSecurity.RunWithElevatedPrivileges(delegate() &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ &amp;nbsp;&lt;span class="Apple-style-span" style="font-family: 'Segoe UI', Verdana, Arial; font-size: 14px;"&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPSite site = new SPSite("http://spsite/siteA");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWeb web = site.OpenWeb();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["Orders"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPItem i in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; someTable.Add(i["Name"].toString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Easy, isn't it? Here is the link to the source to get more informations:&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx&lt;/a&gt;&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-5889889815209596439?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/5889889815209596439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/how-to-programmatically-ensure-full.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5889889815209596439?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5889889815209596439?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/how-to-programmatically-ensure-full.html' title='How to programmatically ensure full permission to the list, document etc.'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUcNSH09fSp7ImA9WhdRGEo.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-5789769908973572375</id><published>2011-08-09T01:04:00.000-07:00</published><updated>2011-08-09T01:04:59.365-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-09T01:04:59.365-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint check field value'/><title>"Object reference not set to an instance of an object." - working with SharPoint fields</title><content type='html'>When you somehow work with data in SharePoint list the important thing is that you should beware of empty fields.&lt;br /&gt;
This code seems to be ok and it would perfectly work until one of the "Name" fields wouldn't be empty:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Value of field is: {0}", row["Number"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
Problem is that SharePoint doesn't save empty field as empty string if you would create a new item and left "Number" field empty. So if there is no condition you would get this error: &amp;nbsp;&lt;span class="Apple-style-span" style="color: red;"&gt;Object reference not set to an instance of an object. &lt;/span&gt;because of the field which user didn't fill, the new instance of object wasn't created. (at least, it's what I think, but anybody who knows real reason can comment it ;) )&lt;br /&gt;
For me was the best&amp;nbsp;practice&amp;nbsp;to check every field which user isn't enforced to fill and&amp;nbsp;could be empty.&lt;br /&gt;
You can use this code to check values:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Checks if "Number" field contain any data&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (row["Number"] != null)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Value of field is: {0}", row[myLookupColumnName].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
or another way how to treat empty field is to use try and catch block like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Tries to catch exception&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Value of field is: {0}", row[myLookupColumnName].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch (NullReferenceException ex)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("The field was empty. Error: " + ex.Message);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
If somebody use another way how to check data in field I would be glad to hear it :)&lt;br /&gt;
Happy coding&lt;br /&gt;
David&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-5789769908973572375?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/5789769908973572375/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/object-reference-not-set-to-instance-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5789769908973572375?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5789769908973572375?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/object-reference-not-set-to-instance-of.html' title='&quot;Object reference not set to an instance of an object.&quot; - working with SharPoint fields'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;C0QARXY7eyp7ImA9WhdRFUg.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-5184775399923330468</id><published>2011-08-05T06:35:00.000-07:00</published><updated>2011-08-05T06:35:44.803-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-05T06:35:44.803-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint SPFieldLookup SPFieldLookupvalue SPFieldLookupValueCollection lookup'/><title>How to programmatically manipulate with Lookup field</title><content type='html'>Lookup field allows us to create relation between two lists, but this is not what I want to write about. Here is some source where you can find how to create Lookup field.&lt;br /&gt;
&lt;a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=574"&gt;http://www.dotnetcurry.com/ShowArticle.aspx?ID=574&lt;/a&gt;&lt;br /&gt;
More information about Lookup field you would find if you would search on the Internet.&lt;br /&gt;
But for now let's focus at programmatical part of lookup field.&lt;br /&gt;
&lt;br /&gt;
Data in lookup field are represented as String. This String looks like this: &lt;i&gt;ID;#FieldValue&lt;/i&gt;&lt;br /&gt;
You could write your own class to work with this field but why to code something if there is everything done already :)&lt;br /&gt;
We'll need to use &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx"&gt;SPFieldLookup&lt;/a&gt;&lt;b&gt;, &lt;/b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookupvalue.aspx"&gt;SPFieldLookupValue&lt;/a&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookupvaluecollection.aspx"&gt;SPFieldLookupValueCollection&lt;/a&gt;&amp;nbsp;classes.&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx"&gt;&lt;b&gt;SPFieldLookup&lt;/b&gt;&lt;/a&gt;&lt;b&gt;-&lt;/b&gt; represents a lookup field&lt;br /&gt;
&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookupvalue.aspx"&gt;SPFieldLookupValue&lt;/a&gt;&amp;nbsp;-&amp;nbsp;&lt;/b&gt;contains the value for an &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx"&gt;SPFieldLookup&lt;/a&gt; object&lt;br /&gt;
&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookupvaluecollection.aspx"&gt;SPFieldLookupValueCollection&lt;/a&gt;&amp;nbsp;&lt;/b&gt;-&amp;nbsp;contains the values for an &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx"&gt;SPFieldLookup&lt;/a&gt; object that can contain multiple values&lt;br /&gt;
&lt;br /&gt;
Ok then, it should be enough for the start and lets focus at implementation of this classes. As always you can choose some different ways how you will treat your lookup field.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;If you know that the field is&amp;nbsp;definitely&amp;nbsp;type of Lookup and there is no Multiple selection checked and field is filled(is required field box checked), you can use this simple short code:&lt;/li&gt;
&lt;/ul&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://MySharePointSite"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TestList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//&lt;/i&gt;&lt;i&gt;Loop through all items in the list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPFieldLookupValue myLookup = new SPFieldLookupValue(row["MyLookUpColumn"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Id of my lookup is {0} and value is {1}.", myLookup.LookupId, myLookup.LookupValue);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;In a case you use multiple selection, you would probably want to get all items in your lookup field. For that purpose you can use&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookupvaluecollection.aspx"&gt;SPFieldLookupValueCollection&lt;/a&gt;&amp;nbsp;class which will enable you to go through all items in your lookup field. Here is the code:&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://MySharePointSite"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TestList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Loop through all items in the list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Creates new SPFieldLookupValueCollection instance from our look up field&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPFieldLookupValueCollection myLookupCollection = new SPFieldLookupValueCollection(row["MyLookUpColumn"].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Loop through all items in collection&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPFieldLookupValue myLookup in myLookupCollection)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Id of my lookup is {0} and value is {1}.", myLookup.LookupId, myLookup.LookupValue);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;What should you do if you don't know if your field is type of Lookup? Even here is simple solution because you can go through all fields in your list and check for particular dataType. Actually this doesn't involve just Lookup field because you can use it whenever you need to find out what data types are in your list. It is simple like this:&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;i&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://&lt;/i&gt;&lt;i&gt;MySharePointSite&lt;/i&gt;&lt;i&gt;"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TestList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Title of our lookup column&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string myLookupColumnName = string.Empty;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Name of field to check if it is type of lookup&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string fieldToCheckForLookup = "TestLookup";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Loop through all fields in list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPField field in list.Fields)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Find Lookup field type&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (field is SPFieldLookup)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (field.Title == fieldToCheckForLookup)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //do something clever with our lookup field&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Our field is type of lookup.");&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myLookupColumnName = field.Title;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (myLookupColumnName != string.Empty)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem row in list.Items)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Tries to get data from field&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Creates new SPFieldLookupValueCollection instance from our look up field&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPFieldLookupValueCollection myLookupCollection = new SPFieldLookupValueCollection(row[myLookupColumnName].ToString());&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Loop through all items in collection&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPFieldLookupValue myLookup in myLookupCollection)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Id of my lookup is {0} and value is {1}.", myLookup.LookupId, myLookup.LookupValue);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch(Exception ex)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("An error occured: " + ex.Message);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("{0} field was not type of lookup.", fieldToCheckForLookup);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
I think there is more ways how to work with lookup field but this definitely works for me :)&lt;br /&gt;
Ok, that should be all. If you would find it interesting or helpful I would be glad, but if there is something you don't agree with please comment it or let me know ;)&lt;br /&gt;
David&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-5184775399923330468?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/5184775399923330468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/how-to-programmatically-manipulate-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5184775399923330468?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/5184775399923330468?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/how-to-programmatically-manipulate-with.html' title='How to programmatically manipulate with Lookup field'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DkIFRnYzeSp7ImA9WhdRFEs.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-7965332251874713260</id><published>2011-08-04T06:28:00.000-07:00</published><updated>2011-08-04T06:28:37.881-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T06:28:37.881-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint update delete item list'/><title>Add, update and delete item from the SharePoint list</title><content type='html'>It certainly isn't anything new and everything you can find at Microsoft documentation, but I just wanted to group some often used pieces of code onto one place. So it's mostly my knowledge base :)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ADD ITEM&lt;/b&gt;&lt;br /&gt;
------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://yourSPSite"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TitleOfYourList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPListItem listItem;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Add new item to the list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; listItem = list.Items.Add();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Fill values in a new item&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; listItem["Title"] = "New title";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Save it&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; listItem.Update();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;UPDATE ITEM&lt;/b&gt;&lt;br /&gt;
------------------------------------&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://yourSPSite"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TitleOfYourList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPListItem item in list.Items)&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (item["Title"].ToString() == "YourTitleToUpdate")&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Change something&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item["Title"] = "YourNewTitle";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Save it&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.Update();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;DELETE ITEM&lt;/b&gt;&lt;br /&gt;
------------------------------------&lt;br /&gt;
This part is little bit tricky and maybe it will not look like as you are expecting.&lt;br /&gt;
If you would use foreach loop to go through your items you would see error message like this:&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 11px; line-height: 16px;"&gt;&lt;span style="color: red; font-weight: bold;"&gt;Collection was modified; enumeration operation may not execute.&lt;/span&gt;&lt;span style="color: red; font-weight: bold;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;because whenever item is deleted the number of items in foreach loop is changed.&lt;br /&gt;
If you would use for loop and count upward you wouldn't get error message but if you would want to delete all items from the list some items would be skipped and remained in the list.&lt;br /&gt;
You should use for loop and count downward then you will be able to delete all items or just item depending on your condition.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;i&gt; &amp;nbsp; //Open site&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPSite site = new SPSite("http://yourSPSite"))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Open web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; using (SPWeb web = site.OpenWeb())&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Get your list&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPList list = web.Lists["TitleOfYourList"];&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Count downward to go through all items&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = list.Items.Count - 1; i &amp;gt;= 0; i--)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Delete just the items with title "Test"&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (list.Items[i].Title == "Test")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine("Deleting " + list.Items[i].Title);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; list.Items.Delete(i);&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
Happy coding ;)&lt;br /&gt;
David&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-7965332251874713260?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/7965332251874713260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/add-update-and-delete-item-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/7965332251874713260?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/7965332251874713260?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/add-update-and-delete-item-from.html' title='Add, update and delete item from the SharePoint list'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CEAGRn4_fyp7ImA9WhdRGUs.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-6021240768560455838</id><published>2011-08-04T02:47:00.000-07:00</published><updated>2011-08-10T00:52:07.047-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-10T00:52:07.047-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint current user permission level greater or equal role'/><title>Check if current user has permission level greater or equal to given value</title><content type='html'>Microsoft SharePoint 2007 is a little bit complicated with permissions. Roles are one important part about it. Roles define user's permission to the site or files. MS SharePoint contains five permission level by default(Full Control, Design, Contribute, Read, Limited Access).&amp;nbsp;Also you can create your own groups and set them their permission level. I will not describe Microsoft SharePoint permission logic here because you can easily google it and you would found a lot of useful sources.&lt;br /&gt;
Here is the some for the start:&lt;br /&gt;
&lt;a href="http://office.microsoft.com/en-us/windows-sharepoint-services-help/permission-levels-and-permissions-HA010100149.aspx"&gt;http://office.microsoft.com/en-us/windows-sharepoint-services-help/permission-levels-and-permissions-HA010100149.aspx&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms252445(v=vs.80).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms252445(v=vs.80).aspx&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://office.microsoft.com/en-us/sharepoint-server-help/about-managing-sharepoint-groups-and-users-HA010021579.aspx"&gt;http://office.microsoft.com/en-us/sharepoint-server-help/about-managing-sharepoint-groups-and-users-HA010021579.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Let's imagine&amp;nbsp;hypothetical&amp;nbsp;project. You should create webPart which would view some data (data source is SP list somewhere) and that data should be editable for users who has at least Contribute permission level to the site. So whenever you render webPart you need to check user's permission level at first. This code should help you to check if the permission level of current user is greater or equal to another permission level.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;bool isCurrentUserRolesGreaterOrEqualThan(string role)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //User's permission level&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool limitedAccess = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool read = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool contribute = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool design = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool fullControl = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Current web&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPWeb web = SPContext.Current.Web;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Gets all user's roles&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Role definitions to compare with user's roles&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Checks user's permission level-Read, Contribute, Design, Full Control, and Limited Access&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (usersRoles.Contains(roleDefinitions["Read"]))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; read = true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (usersRoles.Contains(roleDefinitions["Contribute"]))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;i&gt;contribute&amp;nbsp;&lt;/i&gt;&lt;i&gt;= true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (usersRoles.Contains(roleDefinitions["Design"]))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;i&gt;design&amp;nbsp;&lt;/i&gt;&lt;i&gt;= true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (usersRoles.Contains(roleDefinitions["Full Control"]))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;i&gt;fullControl&amp;nbsp;&lt;/i&gt;&lt;i&gt;= true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (usersRoles.Contains(roleDefinitions["Limited Access"]))&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;i&gt;limitedAccess&amp;nbsp;&lt;/i&gt;&lt;i&gt;= true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Compares given role with user's permission level&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (role == "Limited Access")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (limitedAccess || read || contribute || design || fullControl)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(role == "Read")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (read || contribute || design || fullControl)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(role == "Contribute")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (contribute || design || fullControl)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(role == "Design")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (design || fullControl)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(role == "Full Control")&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (fullControl)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPUser currentUser = web.CurrentUser;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (currentUser.IsSiteAdmin)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
OK. And that's all :) I hope it could help somebody...&lt;br /&gt;
Happy coding&lt;br /&gt;
David&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-6021240768560455838?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/6021240768560455838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/check-if-current-user-has-permission.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6021240768560455838?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6021240768560455838?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/check-if-current-user-has-permission.html' title='Check if current user has permission level greater or equal to given value'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DkEDSH89fyp7ImA9WhdRFEs.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-2841732973431567099</id><published>2011-08-04T01:32:00.000-07:00</published><updated>2011-08-04T06:31:19.167-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T06:31:19.167-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint groups user'/><title>Microsoft SharePoint 2007 - Current user's groups</title><content type='html'>This isn't anything new, but maybe it could help someone. Sometimes your application requires to get membership of current user. In that case you could use code bellow.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;i&gt;&amp;nbsp; //searching result&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bool containsGroupName = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //current context&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPContext currentContext;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Gets the current context&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentContext = SPContext.Current;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch (InvalidOperationException)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentContext = null;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (currentContext != null &amp;amp;&amp;amp; currentContext.Web.CurrentUser != null)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //loop through user's groups and comparing if some group contain required name&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SPGroupCollection usersGroups = currentContext.Web.CurrentUser.Groups;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (SPGroup group in usersGroups)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ("GroupToFind" == group.Name)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; containsGroupName = true;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-2841732973431567099?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/2841732973431567099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/08/microsoft-sharepoint-current-users.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/2841732973431567099?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/2841732973431567099?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/08/microsoft-sharepoint-current-users.html' title='Microsoft SharePoint 2007 - Current user&apos;s groups'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUQDSHczeCp7ImA9WhdRFEk.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-4853565271328877709</id><published>2011-07-26T05:19:00.000-07:00</published><updated>2011-08-04T01:42:59.980-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T01:42:59.980-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharePoint LINQ System.NullReferenceException'/><title>LINQ and System.NullReferenceException</title><content type='html'>LINQ is very useful, but it was also cause of my problems. I think almost everybody already have seen this exception:&amp;nbsp;&lt;i&gt;System.NullReferenceException: Object reference not set to an instance of an object&lt;/i&gt;. You can google it and I think you would find many useful information :) But it was not useful for me at all. I was stuck for some hours with this error message.&lt;br /&gt;
The reason was simple. Before some months ago I created application with connect to database and I was using LINQ to querying. I made some simple query like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;var query = &amp;nbsp;from table in sql08.minussevenshorts&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where table.DATUM == yesterday&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group table by table.order into g&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select new&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FirstColum = g.Key,&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CountOfOrders = (g.Sum(p =&amp;gt; p.MONEY) / g.Sum(p =&amp;gt; p.STUFFS)),&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/i&gt;&lt;br /&gt;
everything works fine so I was satisfied at the moment. But after some months the error&amp;nbsp;occurred and I didn't know reason at all. I checked my source code and database was only place where could be a problem. As I thought this really was cause of error because if you look at CountOfOrders column, there is not any condition which prevent before dividing by zero. When I was programming application I didn't even expecting that&amp;nbsp;&lt;i&gt;g.Sum(p =&amp;gt; p.STUFFS)&lt;/i&gt; could return zero but data was changed&amp;nbsp;when time goes by. I added simple condition and everything works fine now. Here it is:&lt;br /&gt;
&lt;i&gt;CountOfOrders&amp;nbsp;= (g.Sum(p =&amp;gt; p.STUFFS) == 0 ? 0 : g.Sum(p =&amp;gt; p.MONEY) / g.Sum(p =&amp;gt; p.STUFFS)),&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So this really was lesson for me. You should not trust that data will be same as you are expecting it. So check it all the time ;) I think if you need to make more counting operations, it is better to make your own class and work with raw data from database. But I am not sure what would be faster if you need just ordinary counting operations as I showed above. I think in that case is better to count inside querying.&lt;br /&gt;
I hope that maybe it would help somebody :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-4853565271328877709?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/4853565271328877709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/07/linq-and-systemnullreferenceexception.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4853565271328877709?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/4853565271328877709?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/07/linq-and-systemnullreferenceexception.html' title='LINQ and System.NullReferenceException'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;Dk8DSH86fSp7ImA9WhdRFEs.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-940791406883755119</id><published>2011-07-22T07:08:00.000-07:00</published><updated>2011-08-04T06:34:39.115-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T06:34:39.115-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint update item disable event firing'/><title>Update item inside onItemChanged Activity - Disable event firing</title><content type='html'>Sometimes you need to react on item changed event and maybe you want program some application logic then. But problem is when you want to update item inside onItemChanged activity, probably you would do something like that (or maybe just I did it at first time :) )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;workflowProperties.Item["Title"] = "Title was changed";&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;workflowProperties.Item.Update();&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This particular code would seems to work fine but new onItemChange event is fired over and over. And it really isn't good solution I think. If you don't want to save just simple string like I did above. And if you want to interact with some particular changes in item, it would probably cause some mess with your application logic because of executing onItemChanged code.&lt;br /&gt;
&lt;br /&gt;
You could easily use SystemUpdate() function to prevent event firing&lt;br /&gt;
workflowProperties.Item.SystemUpdate();&lt;br /&gt;
but unlucky for me it doesn't work at all.&lt;br /&gt;
&lt;br /&gt;
As always there is another solution to achieve this. You can make your own Event firing class to disable event firing.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;namespace CustomNamespace&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;public class EventFiringOperations : SPItemEventReceiver&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; public&amp;nbsp;EventFiringOperations()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; public void disableEventFiring()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //Obsolete way&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //this.DisableEventFiring();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //Better (VS2010) (Visual studio would tell you for sure ;) )&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; this.EventFiringEnabled = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; public void enableEventFiring()&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; {&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //Obsolete&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //this.EnableEventFiring();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; //Better&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;this.EventFiringEnabled = false;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; }&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;public class CustomClass&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;{&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; //...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp;EventFiringOperations&amp;nbsp;eventFiring = new&amp;nbsp;EventFiringOperations();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp;eventFiring.disableEventFiring();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; item.Update(); &amp;nbsp; &amp;nbsp; //Now you can update :)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp;&amp;nbsp;eventFiring.enableEventFiring();&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; //...&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;}&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This won't help you only if you will update item inside onItemChanged activity code, but whenever you don't want to fire event when you updating item.&lt;br /&gt;
I have posted it here more for my benefit, but if anyone finds it useful then great.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-940791406883755119?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/940791406883755119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/07/update-item-inside-onitemchanged.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/940791406883755119?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/940791406883755119?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/07/update-item-inside-onitemchanged.html' title='Update item inside onItemChanged Activity - Disable event firing'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DUYDR3s4fCp7ImA9WhdRFEk.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-6958617180642168588</id><published>2011-07-22T04:50:00.000-07:00</published><updated>2011-08-04T01:39:36.534-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T01:39:36.534-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='workflow reset time service'/><title>Loop inside workflow doesn't execute a changed code</title><content type='html'>Recently I was solving this issue:&lt;br /&gt;
Simply I have two parallel while loops. Both use the same condition. First loop contain just onWorkflowItemChanged and second one contain code block after logToHistoryListActivity and then delayActivity.&lt;br /&gt;
When I deploy and run workflow everything seems work fine but when I change code at first time is used the new code (let's say I just comment part which write something to the list) but every other loop is different and and old code is executed (even I comment that part).&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;div&gt;This problem takes me while to solve, but solution is very easy.&lt;/div&gt;&lt;div&gt;Everything what you need to do is &lt;u style="font-weight: bold;"&gt;reset time service.&lt;/u&gt;&amp;nbsp;Here are commands to do that:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;i&gt;SharePoint 2007: net stop SPTimerV3 / net start SPTimerV3&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;SharePoint 2003: net stop SPTimer / net start SPTimer&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;SharePoint 2010: net stop SPTimerV4 net start SPTimerV4&lt;/i&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The reason why old error is executed is that DelayActivity hibernates workflow and sets a new timer job. But when I changed the code the old time job was executed. That is reason why you should reset time service and "delete" old timer jobs to prevent them occurring again.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Hope this helps somebody ;)&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/8542921819638684666-6958617180642168588?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/6958617180642168588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/07/loop-inside-workflow-doesnt-execute.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6958617180642168588?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/6958617180642168588?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/07/loop-inside-workflow-doesnt-execute.html' title='Loop inside workflow doesn&apos;t execute a changed code'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DE8GSHg-eip7ImA9WhdRFEk.&quot;'><id>tag:blogger.com,1999:blog-8542921819638684666.post-492380022987447998</id><published>2011-07-22T04:22:00.000-07:00</published><updated>2011-08-04T01:33:49.652-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-08-04T01:33:49.652-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='stsadm commands wsp sharePoint solution feature install deploy activate deactivate retract delete'/><title>STSADM commands to install WSP file</title><content type='html'>Everyone who works with MS SharePoint need from time to time works with WSP files. Here are some useful STSADM commands.&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
1. Add the solution&lt;br /&gt;
stsadm -o addsolution -filename {WSPFILENAME}&lt;br /&gt;
2. Deploy the solution&lt;br /&gt;
stsadm -o deploysolution -name {WSPFILENAME} -url {SITEURL}&lt;br /&gt;
3. Install the feature&lt;br /&gt;
stsadm -o installfeature -filename {FeatureFolder}\feature.xml&lt;br /&gt;
4. Activate the feature&lt;br /&gt;
stsadm -o activatefeature -id {FEATUREID} -url {SITEURL} -force&lt;br /&gt;
5. Deactive the feature&lt;br /&gt;
Stsadm.exe -o deactivatefeature -filename “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\{YourFeatureName}\feature.xml” -url http://servername/&lt;br /&gt;
6.Uninstall the feature&lt;br /&gt;
stsadm -o uninstallfeature -filename&lt;br /&gt;
7.Retract Solution&lt;br /&gt;
stsadm -o retractsolution -name [-url] [-allcontenturls] [-time] [-immediate]&lt;br /&gt;
8.Delete Solution&lt;br /&gt;
stsadm -o deletesolution -name&lt;br /&gt;
-----------------------------------------&lt;br /&gt;
Source:&lt;br /&gt;
&lt;a href="http://littletalk.wordpress.com/2008/12/16/steps-to-install-wsp-file-in-stsadm/"&gt;http://littletalk.wordpress.com/2008/12/16/steps-to-install-wsp-file-in-stsadm/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8542921819638684666-492380022987447998?l=david-row.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://david-row.blogspot.com/feeds/492380022987447998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://david-row.blogspot.com/2011/07/stsadm-commands-to-install-wsp-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/492380022987447998?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8542921819638684666/posts/default/492380022987447998?v=2'/><link rel='alternate' type='text/html' href='http://david-row.blogspot.com/2011/07/stsadm-commands-to-install-wsp-file.html' title='STSADM commands to install WSP file'/><author><name>David Row</name><uri>http://www.blogger.com/profile/11823168125836063574</uri><email>noreply@blogger.com</email></author><thr:total>0</thr:total></entry></feed>