<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.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:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;A0IMQH88fyp7ImA9WhRUFUQ.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636</id><updated>2012-01-26T17:39:41.177Z</updated><category term="logging" /><category term="Visual Studio Tools for Office" /><category term="designer" /><category term="Visual Studio" /><category term="Managed Meta-Data" /><category term="webpart" /><category term="Check in" /><category term="SQL" /><category term="list" /><category term="CheckBoxList" /><category term="strip" /><category term="GUID" /><category term="lists" /><category term="SQL Server" /><category term="Arrays" /><category term="meta data" /><category term="2003" /><category term="URI" /><category term="column" /><category term="all users" /><category term="stopwatch" /><category term="form" /><category term="reference values" /><category term="c#" /><category term="define" /><category term="VSTO" /><category term="sharepoint" /><category term="GetListItems" /><category term="Web part" /><category term="updatelist" /><category term="class" /><category term=".net" /><category term="code" /><category term="Jquery" /><category term="SSIS" /><category term="default" /><category term="2008" /><category term="difference" /><category term="taxonomy" /><category term="deploy" /><category term="colour" /><category term="variable" /><category term="threads" /><category term="MySQL" /><category term="SPListItemCollection" /><category term="table name" /><category term="fields" /><category term="Office" /><category term="GetListCollection" /><category term="example" /><category term="deployment" /><category term="Controls" /><category term="URL" /><category term="2010" /><category term="syntax highlighting" /><category term="CAML" /><category term="web services" /><category term="BackgroundWorker" /><category term="RichTextBox" /><category term="batch" /><category term="SOAP" /><category term="VBA" /><category term="RAG" /><category term="Timer" /><category term="integration" /><category term="blogger" /><category term="Content Type" /><category term="ContentType" /><category term="segments" /><category term="runtime" /><category term="color" /><category term="VB.Net" /><category term="openquery" /><title>The Simple Programmer</title><subtitle type="html">Code examples and tips for Microsoft development platforms, especially Sharepoint.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://the-simple-programmer.blogspot.com/" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/TheSimpleProgrammer" /><feedburner:info uri="thesimpleprogrammer" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;CUEHQ38-eCp7ImA9WhRREUU.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-8935308687922728515</id><published>2011-11-25T01:09:00.001Z</published><updated>2011-11-25T01:13:52.150Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-25T01:13:52.150Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Managed Meta-Data" /><category scheme="http://www.blogger.com/atom/ns#" term="Check in" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><title>Integration between Word 2003 and SharePoint 2010 using Managed Meta-data</title><content type="html">You cannot check out/edit/check in directly from Word 2003 if you are using managed meta-data in the list.&amp;nbsp; Word 2003 does not seem to integrate properly with managed meta-data columns, and will refuse to check in the document.&lt;br /&gt;
&lt;br /&gt;
This leaves teh document in an unsaved, checked out state if a user attempts to edit it directly from Sharepoint.&lt;br /&gt;
&lt;br /&gt;
My only solution to this has been to create a new content type and remove the managed meta-data from it.&amp;nbsp; &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/7799238193115123636-8935308687922728515?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SkQgjBRErNdf9aJuGU0L0IB98Oc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SkQgjBRErNdf9aJuGU0L0IB98Oc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SkQgjBRErNdf9aJuGU0L0IB98Oc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SkQgjBRErNdf9aJuGU0L0IB98Oc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/wJQgnuQQpnY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/8935308687922728515/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/11/integration-between-word-2003-and.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/8935308687922728515?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/8935308687922728515?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/wJQgnuQQpnY/integration-between-word-2003-and.html" title="Integration between Word 2003 and SharePoint 2010 using Managed Meta-data" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/11/integration-between-word-2003-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkIDRHY-fip7ImA9WhRTFEk.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5170915923254056324</id><published>2011-11-04T21:02:00.000Z</published><updated>2011-11-04T21:02:55.856Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-04T21:02:55.856Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="Content Type" /><category scheme="http://www.blogger.com/atom/ns#" term="GUID" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><title>C# function to get the Content Type GUID from a Sharepoint list using web services</title><content type="html">Simple helper function to get the GUID of a list from Sharepoint web services.&lt;br /&gt;
&lt;br /&gt;
Note that in the code below I have a class level object pointing to the Lists.asmx web service called m_listService already established , but I have left in the code to establish this connection in the comments as an example.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;string GetListContentTypeGuid(string listName, string listID, string contentTypeName)
        {
            string defaultGuid = "";
            
            try
            {
                
                //ListsService.Lists listService = new ListsService.Lists();
                //listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                //XmlNode ndList = listService.GetList(fileInfo.m_listInfo.m_listName);
                //XmlNode ndVersion = ndList.Attributes["Version"];

                XmlNode contentTypes = m_listService.GetListContentTypes(listID, "anything");

                // Loop through the fields
                foreach (XmlNode node in contentTypes)
                {
                    System.Diagnostics.Debug.Print(node.Attributes["Name"].Value.ToString());
                    if (node.Attributes["Name"].Value.ToString() == contentTypeName)
                    {
                        defaultGuid = node.Attributes["ID"].Value.ToString();
                        break;
                    }
                }
                
            }
            catch (Exception ex)
            {

                throw new Exception("ERROR: Reading content types from target site.\r\n"
                    + ex.Message + "\r\nDetails: " + ex.InnerException + "\r\n" +
                    "Check the settings file to ensure that the list settings match the target site.", ex);

            }
            return defaultGuid;
        }
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5170915923254056324?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WP8lg1MeszDWUwwYAqKu-WOjmw4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WP8lg1MeszDWUwwYAqKu-WOjmw4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WP8lg1MeszDWUwwYAqKu-WOjmw4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WP8lg1MeszDWUwwYAqKu-WOjmw4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/8ZVczeeaQWI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5170915923254056324/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/11/c-function-to-get-content-type-guid.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5170915923254056324?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5170915923254056324?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/8ZVczeeaQWI/c-function-to-get-content-type-guid.html" title="C# function to get the Content Type GUID from a Sharepoint list using web services" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/11/c-function-to-get-content-type-guid.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkYGRH48eSp7ImA9WhdSEUw.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-8184586463637120566</id><published>2011-07-20T00:00:00.004+01:00</published><updated>2011-07-20T00:28:45.071+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-20T00:28:45.071+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="2010" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><category scheme="http://www.blogger.com/atom/ns#" term="taxonomy" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="CAML" /><title>Sharepoint 2010 managed meta-data taxonomy field data using web services</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=B0040SXV5E&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;Sharepoint 2010 includes a very useful new concept: managed meta-data.  This allows you to build taxonomic hierarchies, and provide document routing based on the meta-data.&lt;br /&gt;
&lt;br /&gt;
Unfortunately, it seems that using this field type using a web service call is extremely complicated, and hardly seems to be documented at all (this is so typical of Sharepoint stuff...).&amp;nbsp; Microsoft have given us a new web service class ("taxonomyclientservice") but there hardly any documentation on it all (&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.webservices.taxonomyclientservice.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.webservices.taxonomyclientservice.aspx&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is an example that I have managed to get working (after MUCH trial and error) that will hopefully help you to do the following:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt; opens a list using the Lists web service,&amp;nbsp;&lt;/li&gt;
&lt;li&gt;iterates through the fields in the default content type for the list (you can remove this bit and just iterate through the fields in the list if you like),&lt;/li&gt;
&lt;li&gt;if it finds a "TaxonomyFieldType" field, it then gets the "Shared Service ID" (GUID of managed meta-data service) and Term Set ID (GUID of term set defined on this field) required to run the Taxonomy web service call&lt;/li&gt;
&lt;li&gt;sets up the CAML to run the Taxonomy web service call,&lt;/li&gt;
&lt;li&gt;retrieves the taxonomy data for that field in XML.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;&amp;nbsp;I do not try to analyse what the taxonomy XML means - that is for another day! &lt;br /&gt;
&lt;br /&gt;
Note that all my web service proxies are called "ListService" and "Taxonomys".&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;//get list data from webservice
ListService.Lists listService = new ListService.Lists();
// Use your own list name
XmlNode list = listService.GetList(&amp;quot;My List Name&amp;quot;);

// Let's have a look at it
System.Diagnostics.Debug.Print(list.OuterXml);

// Get the content types for this list
//Get our defined content type (see previous post on how to do this - you need your own values here!)
string contentTypeGuid = GetListContentTypeGuid(&amp;quot;My List Name&amp;quot;, &amp;quot;{GUID}&amp;quot;, &amp;quot;My Content Type&amp;quot;);

// Now get content type definition 
XmlNode contentType = m_listService.GetListContentType(mylistinfo.m_listName, contentTypeGuid);

//Get the fields from the content type
XmlNodeList nodes = RunXPathQuery(contentType, &amp;quot;//sp:Field&amp;quot;);

// Loop through the fields in the content type
foreach (XmlNode node in nodes)
{
 // This stuff just sets up some variables based on the content type and skips over hidden fields
 string Name = node.Attributes[&amp;quot;Name&amp;quot;].Value;
 if (Name == &amp;quot;ContentType&amp;quot;) continue;
 
 string ID = node.Attributes[&amp;quot;ID&amp;quot;].Value;

 if (string.IsNullOrEmpty(ID) || string.IsNullOrEmpty(Name))
     continue;

 bool hidden = false;
 bool ReadOnly = false;
 try { hidden = Convert.ToBoolean(node.Attributes[&amp;quot;Hidden&amp;quot;].Value); }
 catch { }
 try { ReadOnly = Convert.ToBoolean(node.Attributes[&amp;quot;ReadOnly&amp;quot;].Value); }
 catch { }

 if (hidden || ReadOnly)
     continue;

 string ShowInFileDlg = &amp;quot;&amp;quot;;
 try { ShowInFileDlg = node.Attributes[&amp;quot;ShowInFileDlg&amp;quot;].Value; }
 catch { }
 if (ShowInFileDlg == &amp;quot;FALSE&amp;quot;) continue;


 string StaticName = node.Attributes[&amp;quot;StaticName&amp;quot;].Value;
 string DisplayName = node.Attributes[&amp;quot;DisplayName&amp;quot;].Value;

 
 // Now we can check the &amp;quot;Type&amp;quot; attribute
 string FieldType = node.Attributes[&amp;quot;Type&amp;quot;].Value;

 if (FieldType == &amp;quot;TaxonomyFieldType&amp;quot;)
 {
     // WE HAVE A TAXONOMY FIELD!!!

     // Lets get the shared service ID and the termset ID from teh List schema
     string sharedServiceIds = &amp;quot;&amp;quot;;
     string termSetId = &amp;quot;&amp;quot;; 
     // jump a few nodes to get the correct bit of the schema (included for clarity)
     XmlNode childNode =  node.ChildNodes[1];
     XmlNode termNodes = childNode.ChildNodes[0];

     //Loop through these nodes until we find the information we need
     foreach (XmlNode term in termNodes.ChildNodes)
     {
         System.Diagnostics.Debug.Print(&amp;quot;term = &amp;quot; + term.ChildNodes[0].InnerText.ToString());
         if (term.ChildNodes.Count &amp;gt; 1)
         {
             System.Diagnostics.Debug.Print(&amp;quot;value = &amp;quot; + term.ChildNodes[1].InnerText.ToString());
             if (term.ChildNodes[0].InnerText.ToString() == &amp;quot;SspId&amp;quot;)
             {
                 // Get shared services ID from list
                 sharedServiceIds = term.ChildNodes[1].InnerText.ToString();
             }
             if (term.ChildNodes[0].InnerText.ToString() == &amp;quot;TermSetId&amp;quot;)
             {
                 // Get Term Set ID from list
                 termSetId = term.ChildNodes[1].InnerText.ToString();
             }
         }
  
     }
     
  
     int lcid = System.Globalization.CultureInfo.CurrentUICulture.LCID;
     string serverTermSetTimeStampXml = &amp;quot;&amp;quot;;


     string termStoreIds = &amp;quot;&amp;lt;termStoreIds&amp;gt;&amp;lt;termStoreId&amp;gt;&amp;quot; + sharedServiceIds + &amp;quot;&amp;lt;/termStoreId&amp;gt;&amp;lt;/termStoreIds&amp;gt;&amp;quot;;
     string termSetIds = &amp;quot;&amp;lt;termSetIds&amp;gt;&amp;lt;termSetId&amp;gt;&amp;quot; + termSetId + &amp;quot;&amp;lt;/termSetId&amp;gt;&amp;lt;/termSetIds&amp;gt;&amp;quot;;
     //Always set timestamp to this
     string oldtimestamp = &amp;quot;&amp;lt;timeStamps&amp;gt;&amp;lt;timeStamp&amp;gt;633992461437070000&amp;lt;/timeStamp&amp;gt;&amp;lt;/timeStamps&amp;gt;&amp;quot;;
     //Always set version to 1
     string clientVersion = &amp;quot;&amp;lt;versions&amp;gt;&amp;lt;version&amp;gt;1&amp;lt;/version&amp;gt;&amp;lt;/versions&amp;gt;&amp;quot;;
     string timeStamp = &amp;quot;&amp;quot;;

     // Taxonomy web service!!
     Taxonomys.Taxonomywebservice taxonomy = new Taxonomys.Taxonomywebservice();
     taxonomy.Credentials = System.Net.CredentialCache.DefaultCredentials;
     string resultXML = taxonomy.GetTermSets(termStoreIds, termSetIds, lcid, oldtimestamp, clientVersion, out timeStamp);



     //Loop through the XML
     string termValue = &amp;quot;MHA&amp;quot;;
     string termGUID = &amp;quot;&amp;quot;;
     string parentID = &amp;quot;&amp;quot;;
     XmlDocument termSetXML = new XmlDocument();
     termSetXML.LoadXml(resultXML);
     XmlNodeList terms = termSetXML.GetElementsByTagName(&amp;quot;T&amp;quot;);
     foreach (XmlNode term in terms)
     {
         string termName = term.FirstChild.FirstChild.Attributes[&amp;quot;a32&amp;quot;].Value;
         termGUID = term.Attributes[&amp;quot;a9&amp;quot;].Value;
         try
         {
             parentID = term.Attributes[&amp;quot;a25&amp;quot;].Value;
         }
         catch (Exception)
         {
             parentID = &amp;quot;&amp;quot;;
     
         }
  
         System.Diagnostics.Debug.Print(&amp;quot;termName = &amp;quot; + termName + &amp;quot;, termGUID = &amp;quot; + termGUID + &amp;quot;, parentID = &amp;quot; + parentID);   
     }                          
     
 }
}

&lt;/pre&gt;&lt;br /&gt;
If you would like to know how to analyse the attribute codes returned in the XML, then take a look at this blog entry: &lt;a href="http://blogs.solidq.com/sharepoint/Post.aspx?ID=37&amp;amp;title=SharePoint+2010%2C+Managed+Metadata%2C+TaxonomyClientService+in+depth"&gt;http://blogs.solidq.com/sharepoint/Post.aspx?ID=37&amp;amp;title=SharePoint+2010%2C+Managed+Metadata%2C+TaxonomyClientService+in+depth&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470529423&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1430227818&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=B00413PHRI&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470888687&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-8184586463637120566?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Q9RnxfQ7wBSsAhPE_tXaz6wG4EY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Q9RnxfQ7wBSsAhPE_tXaz6wG4EY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Q9RnxfQ7wBSsAhPE_tXaz6wG4EY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Q9RnxfQ7wBSsAhPE_tXaz6wG4EY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/IKWwV2clNH4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/8184586463637120566/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/07/sharepoint-2010-managed-meta-data.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/8184586463637120566?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/8184586463637120566?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/IKWwV2clNH4/sharepoint-2010-managed-meta-data.html" title="Sharepoint 2010 managed meta-data taxonomy field data using web services" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/07/sharepoint-2010-managed-meta-data.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUER3g4fSp7ImA9WhRREUU.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-75979260710867682</id><published>2011-06-02T23:34:00.003+01:00</published><updated>2011-11-25T01:06:46.635Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-25T01:06:46.635Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="default" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="Content Type" /><category scheme="http://www.blogger.com/atom/ns#" term="designer" /><category scheme="http://www.blogger.com/atom/ns#" term="2010" /><title>Mark ContentType as default in Sharepoint Designer 2010</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470643161&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;This is pretty simple stuff, but I just spent ten minutes looking at Sharepoint Designer trying to figure out where I clicked to change the default content type on a list!&amp;nbsp; I guess I'm just not used to the ribbon :)&lt;br /&gt;
&lt;br /&gt;
Google didn't help (probably too easy a problem for it) so I thought I would right this up in case anyone else was suffering.&lt;br /&gt;
&lt;br /&gt;
I've created a content type, here it is associated with a list in Sharepoint Designer:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-YxBKvJltFmI/TegOdZcU8gI/AAAAAAAAAIw/gkw7Lfd4Gls/s1600/ContentTypesPanel.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="103" src="http://4.bp.blogspot.com/-YxBKvJltFmI/TegOdZcU8gI/AAAAAAAAAIw/gkw7Lfd4Gls/s320/ContentTypesPanel.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
But how do I make it default?&amp;nbsp; I finally spotted the option after clicking through endless options in SP designer - the trick is to highlight the content type (and not click on its name to see the content type editor!) and the look at the ribbon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-VwBkSHCicjA/TegO3QDye6I/AAAAAAAAAI0/s7kk9AI8fJ0/s1600/ContentTypesSetAsDefault.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="131" src="http://3.bp.blogspot.com/-VwBkSHCicjA/TegO3QDye6I/AAAAAAAAAI0/s7kk9AI8fJ0/s320/ContentTypesSetAsDefault.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
Hurray!&amp;nbsp; There it is.&lt;br /&gt;
Click on this and we have a new default:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-ZAhbJoo7XvM/TegPBoDRSYI/AAAAAAAAAI4/luO6XQukwfQ/s1600/ContentTypesPanelNowDefault.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="120" src="http://1.bp.blogspot.com/-ZAhbJoo7XvM/TegPBoDRSYI/AAAAAAAAAI4/luO6XQukwfQ/s320/ContentTypesPanelNowDefault.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
I hope this helps some other Sharepoint 2010 newbie.&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470529423&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1430227060&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=B00413PHRI&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735627339&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="align: left; height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-75979260710867682?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/u5pIqi_dhPxO3-evrUAWjYaqEWM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u5pIqi_dhPxO3-evrUAWjYaqEWM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/u5pIqi_dhPxO3-evrUAWjYaqEWM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/u5pIqi_dhPxO3-evrUAWjYaqEWM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/WevFLS6p36M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/75979260710867682/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/06/mark-contenttype-as-default-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/75979260710867682?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/75979260710867682?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/WevFLS6p36M/mark-contenttype-as-default-in.html" title="Mark ContentType as default in Sharepoint Designer 2010" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-YxBKvJltFmI/TegOdZcU8gI/AAAAAAAAAIw/gkw7Lfd4Gls/s72-c/ContentTypesPanel.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/06/mark-contenttype-as-default-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8ARHc9fCp7ImA9Wx9aF0Q.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-1561622775632051165</id><published>2011-03-10T21:51:00.001Z</published><updated>2011-03-10T22:07:25.964Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-10T22:07:25.964Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="Check in" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><category scheme="http://www.blogger.com/atom/ns#" term="meta data" /><title>VBA code to check in a document to Sharepoint and set meta data</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0672321564&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;The following VBA code will upload a file to Sharepoint 2007 using a web service, and then sest some meta data (the title) for that file in the document library.&lt;br /&gt;
Remember, you need to have installed the VBA &lt;a href="http://msdn.microsoft.com/en-us/library/aa192537%28office.11%29.aspx"&gt;Microsoft Office 2003 Web Services Toolkit&lt;/a&gt; and created a reference to the web service in your project before this will work.  See these previous posts for more information on calling Sharepoint web services from VBA:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; &lt;a href="http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html"&gt;VBA code to iterate through the results of GetListCollection web service from Sharepoint 2007&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://the-simple-programmer.blogspot.com/2010/03/set-sharepoint-meta-data-from-vba-using.html"&gt;Set Sharepoint meta-data from VBA using updatelist web service&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;' Change these values to your own
sSourceFile = "C:\mtest.doc"  ' File to upload
sTargetFile = "HTTP://my sharepoint site/Shared%20Documents/mytest.doc" ' Target site, document library and file name


' First set up DOM document containing fields
Dim xmlDoc As New MSXML2.DOMDocument30
xmlDoc.async = False

xmlText = "&amp;lt;root&amp;gt;" &amp;amp; _
"&amp;lt;Batch OnError='Continue' ListVersion='" &amp;amp; iVersionNumber &amp;amp; "' PreCalc='TRUE' xmlns=''&amp;gt;" &amp;amp; _
"&amp;lt;Method ID='1' Cmd='Update'&amp;gt;" &amp;amp; _
"&amp;lt;Field Name='ID' /&amp;gt;" &amp;amp; _
"&amp;lt;Field Name='FileRef'&amp;gt;" &amp;amp; sTargetFile &amp;amp; "&amp;lt;/Field&amp;gt;" &amp;amp; _
"&amp;lt;Field Name='Title'&amp;gt;Uploaded from VBA&amp;lt;/Field&amp;gt;" &amp;amp; _
"&amp;lt;/Method&amp;gt;" &amp;amp; _
"&amp;lt;/Batch&amp;gt;" &amp;amp; _
"&amp;lt;/root&amp;gt;"


xmlDoc.LoadXml (xmlText)
Debug.Print xmlText

' This bit is just for testing
If xmlDoc.parseError.errorCode &amp;lt;&amp;gt; 0 Then

Set myErr = xmlDoc.parseError
MsgBox (myErr.reason)
GoTo fnUpload_Error
Else
MsgBox xmlDoc.XML
End If

' Set up IXMLDOMNodeList
Dim myXMLNodeList As MSXML2.IXMLDOMNodeList
Dim root As MSXML2.IXMLDOMElement


Set root = xmlDoc.documentElement
Set myXMLNodeList = root.ChildNodes

' Create an array of IXMLDOMNodeList
Dim ar_Fields(1) As IXMLDOMNodeList
Set ar_Fields(0) = myXMLNodeList
'Debug.Print "ar_Fields(0) = " &amp;amp; ar_Fields(0)


' Now set up an array of strings to hold the URL
Dim ar_URL(1) As String
ar_URL(0) = sTargetFile

Debug.Print "ar_URL(0) = " &amp;amp; ar_URL(0)
' Set up the results object
Dim myresults() As struct_CopyResult

' Set up the byte array and read the source file into it
Dim ar_Stream() As Byte
ar_Stream = ReadFile(sSourceFile)


' NOW CALL WEB SERVICE
' The follwoing comes from the "Microsoft Office 2003 Web Services Toolkit":
'"ar_DestinationUrls" is an array with elements defined as String
'"ar_Fields" is an array with elements defined as IXMLDOMNodeList
'"ar_Stream" is an array with elements defined as Byte
'"ar_Results" is an array with elements defined as struct_CopyResult
'See Complex Types: Arrays in Microsoft Office 2003 Web Services Toolkit Help
'for details on implementing arrays.
documentId = copyws.wsm_CopyIntoItems(sDocumentPath, ar_URL, ar_Fields, ar_Stream, myresults)
Debug.Print "DocumentID = " &amp;amp; documentId

Dim updateReturn As IXMLDOMNodeList

Set updateReturn = listws.wsm_UpdateListItems(sListID, myXMLNodeList)

Dim xmlReturnDoc As New MSXML2.DOMDocument30
If (updateReturn.Length &amp;gt; 0) Then    
xmlReturnDoc.LoadXml (updateReturn.Item(0).XML)

Dim errorText As String
errorText = xmlReturnDoc.Text
If (errorText &amp;lt;&amp;gt; "0x00000000") Then
MsgBox ("Error: Cannot upload load file to Sharepoint." &amp;amp; vbCrLf &amp;amp; _
"     : " &amp;amp; errorText &amp;amp; vbCrLf &amp;amp; Err.Description &amp;amp; vbCrLf )

End If
End If

' Uncomment for debug information.
'MsgBox ("Return XML = " &amp;amp; xmlReturnDoc.XML)

&lt;/pre&gt;&lt;br /&gt;
I use the following VBA to read the target file in as a byte array:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;Private Function ReadFile(ByVal strFileName As String, Optional ByVal lngStartPos As Long = 1, Optional ByVal lngFileSize As Long = -1) As Byte()
    Dim FilNum As Integer
    FilNum = FreeFile
    Open strFileName For Binary As #FilNum
    If lngFileSize = -1 Then
        ReDim ReadFile(LOF(FilNum) - lngStartPos)  
    Else
        ReDim ReadFile(lngFileSize - 1)
    End If
    Get #FilNum, lngStartPos, ReadFile
    Close #FilNum
End Function
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-1561622775632051165?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lpQ_uX33ZEuVS__g-fo-kxoAaSo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lpQ_uX33ZEuVS__g-fo-kxoAaSo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lpQ_uX33ZEuVS__g-fo-kxoAaSo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lpQ_uX33ZEuVS__g-fo-kxoAaSo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/3SiA-3UBiVs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/1561622775632051165/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/03/vba-code-to-check-in-document-to.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/1561622775632051165?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/1561622775632051165?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/3SiA-3UBiVs/vba-code-to-check-in-document-to.html" title="VBA code to check in a document to Sharepoint and set meta data" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>5</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/03/vba-code-to-check-in-document-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkAGQXc7fip7ImA9WhZbEU4.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5108488780348100256</id><published>2011-02-27T23:34:00.007Z</published><updated>2011-06-15T12:52:00.906+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-15T12:52:00.906+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VSTO" /><category scheme="http://www.blogger.com/atom/ns#" term="deploy" /><category scheme="http://www.blogger.com/atom/ns#" term="deployment" /><category scheme="http://www.blogger.com/atom/ns#" term="all users" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio Tools for Office" /><category scheme="http://www.blogger.com/atom/ns#" term="2003" /><category scheme="http://www.blogger.com/atom/ns#" term="Visual Studio" /><category scheme="http://www.blogger.com/atom/ns#" term="2008" /><category scheme="http://www.blogger.com/atom/ns#" term="Office" /><title>Deploy Office 2003  VSTO add in to All Users using Visual Studio 2008</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=B000OZ0NHQ&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;Deploying VSTO add-ins can be a real pain, at least if you are not using 2010.&amp;nbsp; Having just successfully deployed my first add-in, I thought it would be useful to explain how I did and the resources I used.&lt;br /&gt;
&lt;br /&gt;
Firstly, it is important that you follow the instructions for the appropriate version of Office and Visual Studio that you are using.&amp;nbsp; My example is for a legacy solution using Office 2003, created with VSTO Second Edition (Visual Studio 2008).&amp;nbsp; The general&amp;nbsp; principles are the same for other editions, but the specifics may be subtly different.&lt;br /&gt;
&lt;br /&gt;
To get started, look at the walkthrough here:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/bb332052.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb332052.aspx&lt;/a&gt;&lt;br /&gt;
This is another useful collection of resources:&lt;br /&gt;
&lt;a href="http://xldennis.wordpress.com/2007/03/04/creating-and-deploying-managed-com-add-ins-with-vsto-2005-se-part-vi/"&gt;http://xldennis.wordpress.com/2007/03/04/creating-and-deploying-managed-com-add-ins-with-vsto-2005-se-part-vi/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
This explains how to configure a deployment project in Visual Studio 2008 and set up the additional security package required to grant the add-in full trust.&amp;nbsp; I would recommend you follow the steps in here to create a brand new simple package and get that working first.&amp;nbsp; I created a simple Word 2003 add-in package to test, rather than the suggested Outlook.&lt;br /&gt;
&lt;br /&gt;
The security package can be downloaded from MSDN here:&lt;br /&gt;
&lt;a href="http://code.msdn.microsoft.com/VSTO3MSI"&gt;http://code.msdn.microsoft.com/VSTO3MSI&lt;/a&gt;&lt;br /&gt;
Unpackage the download and you should find a .SLN file that has everything pre-configured.&amp;nbsp; Copy the "SetSecurity" package from here and add it to your solution as explained in the walkthrough.&amp;nbsp; Configure the Setup project's outputs as described, and you should end up with a package that looks something like this:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh3.googleusercontent.com/-MQDK2js4oPQ/TWrbqDyY_ZI/AAAAAAAAAIk/NvbFW2EgrKI/s1600/Word2003AddInOutputs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="175" src="https://lh3.googleusercontent.com/-MQDK2js4oPQ/TWrbqDyY_ZI/AAAAAAAAAIk/NvbFW2EgrKI/s320/Word2003AddInOutputs.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Once you have built your setup package, you can find the .MSI and .EXE files in solution bin/debug (or bin/release) directory.&amp;nbsp;&amp;nbsp; Run the .exe and you should have installed your add-in onto your development machine.&amp;nbsp; Run the appropriate Office application to check that the pop up message appears to confirm this.&amp;nbsp; Your development computer should have all the pre-requisites installed, so if this doesn't work you have probably missed something in the walkthrough, or have perhaps used an incorrect version of the setup project, so go back and double check everything.&amp;nbsp;&amp;nbsp; It is vital that you get a simple version working at this stage, or it will cause you all sorts of problems down the line.&lt;br /&gt;
&lt;br /&gt;
Once you have a simple install project working you can go about making it available to ALL USERS on the machine.&amp;nbsp; This is not&amp;nbsp; covered in the walkthrough,&amp;nbsp; although there is mention of it for newer versions of Office in this excellent blog here:&lt;br /&gt;
&lt;a href="http://blogs.msdn.com/b/mshneer/archive/2008/04/24/deploying-your-vsto-add-in-to-all-users-part-iii.aspx"&gt;http://blogs.msdn.com/b/mshneer/archive/2008/04/24/deploying-your-vsto-add-in-to-all-users-part-iii.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In Office 2003, deploying to all users is actually really simple:&amp;nbsp; all we have to do is copy the registry keys that have automatically been generated for us by Visual Studio in the Setup project from HKCU to HKLM.&amp;nbsp; In practice, this mean highlighting your setup project (called Word2003AddInSetup in my example), right click and choose "View" and "Registry":&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-fVEdRRIqMLo/TWrdj96gtJI/AAAAAAAAAIo/njiyW8duo40/s1600/Word2003AddInRegistry.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="152" src="https://lh6.googleusercontent.com/-fVEdRRIqMLo/TWrdj96gtJI/AAAAAAAAAIo/njiyW8duo40/s320/Word2003AddInRegistry.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;This will open up the registry editor.&amp;nbsp;&amp;nbsp; Now, expand all, and renambe the "Software" key in HKLM to some temporary name (say "SoftwareTESTTESTTEST").&lt;br /&gt;
&lt;br /&gt;
You can now drag the "Software" key from the HKCU leaf to the HKLM leaf.&amp;nbsp; Once done, drag your renamed "SoftwareTESTTESTTEST" key from HKLM to HKCU, and rename this back to "Software".&amp;nbsp; You should now have something that looks like this:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh4.googleusercontent.com/-D40jkaezepY/TWreQn1vhWI/AAAAAAAAAIs/o_mZcVPe3-c/s1600/Word2003AddInHKLM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="174" src="https://lh4.googleusercontent.com/-D40jkaezepY/TWreQn1vhWI/AAAAAAAAAIs/o_mZcVPe3-c/s320/Word2003AddInHKLM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;One thing that is not really very well documented at all, and kept me scratching my head for many days, is that you must set the "InstallAllUsers" property on the setup package to "True".&amp;nbsp; This is obvious, but not mentioned anywhere!&amp;nbsp; &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Fam24tre8VE/TficyFkbVtI/AAAAAAAAAI8/tAA9BKuO_ME/s1600/InstallAllUsers.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-Fam24tre8VE/TficyFkbVtI/AAAAAAAAAI8/tAA9BKuO_ME/s320/InstallAllUsers.png" width="220" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
That's it!&amp;nbsp; Build your setup solution and re-install it (you will have to un-install your original version first).&amp;nbsp; You should now find that any user that logs into the machine will have the add in enabled.&lt;br /&gt;
&lt;br /&gt;
Please note that if you are using Office 2007, this technique does not work - you will have to refer to the blog post linked above to learn how to set up the appropriate registry keys.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1598220470&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0321533216&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5108488780348100256?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ftc4FGtoGCXU6l568mKgoDD1TuI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ftc4FGtoGCXU6l568mKgoDD1TuI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ftc4FGtoGCXU6l568mKgoDD1TuI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ftc4FGtoGCXU6l568mKgoDD1TuI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/5Jd1nAuCCtc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5108488780348100256/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/02/deploy-visual-studio-2008-vsto-add-in.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5108488780348100256?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5108488780348100256?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/5Jd1nAuCCtc/deploy-visual-studio-2008-vsto-add-in.html" title="Deploy Office 2003  VSTO add in to All Users using Visual Studio 2008" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh3.googleusercontent.com/-MQDK2js4oPQ/TWrbqDyY_ZI/AAAAAAAAAIk/NvbFW2EgrKI/s72-c/Word2003AddInOutputs.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/02/deploy-visual-studio-2008-vsto-add-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkUGQH87fip7ImA9Wx9VEE0.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-7986692603534442474</id><published>2011-01-26T00:03:00.000Z</published><updated>2011-01-26T00:03:41.106Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-26T00:03:41.106Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="example" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="batch" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="CAML" /><category scheme="http://www.blogger.com/atom/ns#" term="updatelist" /><category scheme="http://www.blogger.com/atom/ns#" term="GetListItems" /><title>Sharepoint 2007 Batch Update example using web services and CAML</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1590594568&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;Here is an example of running a batch update process on Sharepoint 2007 using web services.  It was written in C# in Visual Studio 2008.&lt;br /&gt;
&lt;br /&gt;
In this example, I take the value of a text field "Date_x0020_of_x0020_Birth", turn this into a DateTime value, and then use this to update the the value of a DateTime field "Date_x0020_of_x0020_Birth0".  Obviously this section of the code will not be particularly generalisable, however I have left in all the code in order to show you the principles involved, and hopefully you will find it useful in building your own batch routines.&lt;br /&gt;
&lt;br /&gt;
In order to get it running, you must create a reference to the Sharepoint Lists web service and call it "ListsService".  The SDK shows you how to do this, and is available here: &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/en/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&amp;amp;displaylang=en&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The GetListItems() method of the Lists web service is used to query the data, and the UpdateListItems() method is used to update items.&lt;br /&gt;
&lt;br /&gt;
I used an XPathNavigator object to filter only rows that contain data.  You could just loop through the nodes if you prefer.&lt;br /&gt;
&lt;br /&gt;
CAML is used to query the Sharepoint list and look for items where the "Date_x0020_of_x0020_Birth" is null.  Tailor this to your own needs.&lt;br /&gt;
For CAML reference, look at the MSDN article here: &lt;a href="http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems%28v=office.12%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems%28v=office.12%29.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The CAML update command uses owshiddenversion, and so is useful in situations where versioning is enabled.  Lists without versioning do not need this field.&lt;br /&gt;
&lt;br /&gt;
If the UpdateListItems command returns an error, in my experience this is usually caused by using an incorrect internal name for a field.&amp;nbsp; You may need to add the &lt;span class="pBody postableBody"&gt;URI prefix "urn:schemas-microsoft-com&lt;wbr&gt;&lt;/wbr&gt;:office:of&lt;wbr&gt;&lt;/wbr&gt;fice#" to the field name (e.g. change line 42 to something like:&amp;nbsp; "&amp;lt;Field Name=\"urn:schemas-microsoft-com&lt;wbr&gt;&lt;/wbr&gt;:office:of&lt;wbr&gt;&lt;/wbr&gt;fice#{4}\"&amp;gt;{5}&amp;lt;/Field&amp;gt;").&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Full code:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Net;

namespace BatchUpdateDOB
{
    class Program
    {
        static string LogFile = "D:\\BatchUpdateLog.txt";  // Log file location

        static void Main(string[] args)
        {
            try
            {
                StatusMessage("Writing log file to: " + LogFile);
           
                // Set up the variables to be used.
                StringBuilder methodBuilder = new StringBuilder();
                string batch = string.Empty;
                DateTime currentDate = DateTime.Now;
                string formattedDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(currentDate);
                string fieldToReference = "Date_x0020_of_x0020_Birth";
                string fieldToUpdate = "Date_x0020_of_x0020_Birth0";

                string batchFormat = "&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt;" +
                  "&amp;lt;ows:Batch OnError=\"Return\"&amp;gt;{0}&amp;lt;/ows:Batch&amp;gt;";

                
                // CAML update command for web service
                string methodFormat = "&amp;lt;Method ID=\"1\" Cmd=\"Update\"&amp;gt;" +
                 "&amp;lt;Field Name=\"ID\"&amp;gt;{1}&amp;lt;/Field&amp;gt;" +
                 "&amp;lt;Field Name=\"FileRef\"&amp;gt;{2}&amp;lt;/Field&amp;gt;" +
                 "&amp;lt;Field Name=\"owshiddenversion\"&amp;gt;{3}&amp;lt;/Field&amp;gt;" +
                 "&amp;lt;Field Name=\"{4}\"&amp;gt;{5}&amp;lt;/Field&amp;gt;" +
                 "&amp;lt;/Method&amp;gt;";

                //UPDATE THESE TWO LINES TO SITE SPECIFIC VALUES
                string siteName = "http://&amp;lt;your site root uri here&amp;gt;";
                string listName = "&amp;lt;your list name here&amp;gt;";

                //string viewName = "";  // No need for viewname
                int rowLimit = 10;       //The number of items returned per batch (not used)

                StatusMessage("Processing " + siteName + ", List: " + listName + "...");

                //Web service setup
                //ListService should be the name of your web service reference
                ListService.Lists listService = new ListService.Lists();
                listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                listService.Url = siteName + "/_vti_bin/Lists.asmx";
                

                //Build CAML query to search for records
                XmlDocument camlDocument = new XmlDocument();
                XmlNode queryNode = camlDocument.CreateElement("Query");
                //queryNode.InnerXml =  "&amp;lt;Where&amp;gt;&amp;lt;IsNull&amp;gt;&amp;lt;FieldRef Name='Date_x0020_of_x0020_Birth'/&amp;gt;&amp;lt;/IsNull&amp;gt;&amp;lt;/Where&amp;gt;";
                //queryNode.InnerXml = "&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name='Country' /&amp;gt;&amp;lt;/OrderBy&amp;gt;";

                XmlNode viewFieldsNode = camlDocument.CreateElement("ViewFields");
                viewFieldsNode.InnerXml = "&amp;lt;FieldRef Name='Title' /&amp;gt;" +
                  "&amp;lt;FieldRef Name='owshiddenversion' /&amp;gt;" +
                  "&amp;lt;FieldRef Name='" + fieldToReference + "' /&amp;gt;" +
                  "&amp;lt;FieldRef Name='" + fieldToUpdate + "' /&amp;gt;" +
                  "&amp;lt;FieldRef Name='FileRef' /&amp;gt;";

                XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");
                queryOptionsNode.InnerXml = "&amp;lt;ViewAttributes Scope=\"Recursive\" /&amp;gt;&amp;lt;IncludeMandatoryColumns&amp;gt;True&amp;lt;/IncludeMandatoryColumns&amp;gt;";

                // Get the GUID of the list
                XmlNode ndListView = listService.GetListAndView(listName, "");
                string listGuid = ndListView.ChildNodes[0].Attributes["Name"].Value;
                string listVersion = ndListView.ChildNodes[0].Attributes["Version"].Value;

                // Run the CAML query
                XmlNode resultNode = listService.GetListItems(listGuid, null, queryNode, viewFieldsNode, rowLimit.ToString(), queryOptionsNode, null);
                // If you want to put a rowlimit on, then use this command:
                //XmlNode resultNode = listService.GetListItems(listGUID, null, queryNode, viewFieldsNode, rowLimit.ToString(), queryOptionsNode, null);

                long totalRecords = 0;
               
                //string itemDOB;
                string dob;
                DateTime dtDOB;
                string owsHiddenVersion;  
                string fullFileRef;
                string owsFileRef;
               

                // Create xpath navigator   
                XPathNavigator navigator = resultNode.CreateNavigator();
                // Set up namespace manager for XPath   
                XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);
                ns.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
                ns.AddNamespace("z", "#RowSetSchema");

                // Select only the z:row nodes
                XmlNodeList nodes = resultNode.SelectNodes("//*[name()='z:row'] ", ns);

                // Iterate through the returned nodes
                foreach (XmlNode node in nodes)
                {
                    string itemID = node.Attributes["ows_ID"].InnerText;
                    try
                    {
                        dob = node.Attributes["ows_" + fieldToReference].InnerText;
                        owsHiddenVersion = node.Attributes["ows_" + "owshiddenversion"].InnerText;
                        owsFileRef = node.Attributes["ows_" + "FileRef"].InnerText;
                        // For some reason my data is returned in the format: 2#/listname/path, 
                        // where 2 seems to be an id or version number, and listname/path points to the file in relation to the root site.
                        // The following strips that out and gets the full path (required for the CAML update)
                        fullFileRef = siteName + "/" + owsFileRef.Remove(0, owsFileRef.IndexOf("#") + 1);
                    }
                    catch(Exception ex)
                    {
                        // Ignore this row
                        //StatusMessage("ERROR: Cannot process: " + node.InnerXml.ToString() + ": " + ex.Message); // If you want to see why, uncomment
                        continue;
                    }

                    if (String.IsNullOrEmpty(dob)) continue;  // Ignore list items with no value

                    dtDOB = Convert.ToDateTime("01/01/1900"); // Set default value for dates before 1900

                    // Convert date text to DateTime
                    try
                    {
                        dtDOB = Convert.ToDateTime(dob);
                    }
                    catch (Exception ex)
                    {
                        StatusMessage("Cannot process: " + siteName + "/" + fullFileRef + " DOB: " + dob + ".  Setting to 01/01/1900. " + ex.Message);
                    }

                    MessageToFile("Processing: " + fullFileRef + ", DOB = " + dob);

                    methodBuilder.AppendFormat(methodFormat, listGuid, itemID, fullFileRef, owsHiddenVersion, fieldToUpdate, SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtDOB));

                    // Put the pieces together.
                    batch = string.Format(batchFormat, methodBuilder.ToString());
                    //MessageToFile(batch);

                    //Build CAML command to update using Web service
                    XmlDocument xmlDoc = new XmlDocument();
                    XmlElement elBatch = xmlDoc.CreateElement("Batch");
                    elBatch.SetAttribute("OnError", "Continue");
                    elBatch.SetAttribute("ListVersion", listVersion.ToString());
                    elBatch.SetAttribute("ViewName", "");
                    elBatch.InnerXml = methodBuilder.ToString();

                    // This line runs the CAML update command
                    XmlNode updatesResponse = listService.UpdateListItems(listGuid, elBatch);
                    if (updatesResponse.FirstChild.FirstChild.InnerText != "0x00000000") throw new Exception("Could not update properties.\n\n" + updatesResponse.InnerText + "\n" + updatesResponse.FirstChild.FirstChild.InnerText);
                    StatusMessage(fullFileRef + " processed...");

                    totalRecords++;
                }
                StatusMessage("Completed - " + totalRecords + " processed.");
            }
            catch (Exception exp)
            {
                StatusMessage("ERROR: " + exp.Message);
                
            }
            
        }

        
        /// &amp;lt;summary&amp;gt;
        /// Display a  message
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="myMessage"&amp;gt;&amp;lt;/param&amp;gt;
        static void StatusMessage(string myMessage)
        {
            Console.WriteLine(myMessage.ToString()); 
            MessageToFile(myMessage);
        }

        /// &amp;lt;summary&amp;gt;
        /// Write message to the log file
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="myMessage"&amp;gt;&amp;lt;/param&amp;gt;
        static void MessageToFile(string myMessage)
        {
            using (StreamWriter sw = new StreamWriter(LogFile, true))
            {
                DateTime now = DateTime.Now;
                sw.WriteLine(now.ToString() + ": " + myMessage.ToString());
            }
        }
    }
}

&lt;/pre&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0672329034&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735623201&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-7986692603534442474?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/F9x5MNFiVlPFb0o9DZS7G8E6qWs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F9x5MNFiVlPFb0o9DZS7G8E6qWs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/F9x5MNFiVlPFb0o9DZS7G8E6qWs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F9x5MNFiVlPFb0o9DZS7G8E6qWs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/VvYlVTT3Vr8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/7986692603534442474/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/01/sharepoint-2007-batch-update-example.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7986692603534442474?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7986692603534442474?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/VvYlVTT3Vr8/sharepoint-2007-batch-update-example.html" title="Sharepoint 2007 Batch Update example using web services and CAML" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/01/sharepoint-2007-batch-update-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMCSHY-cSp7ImA9Wx9XF0U.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-16676474789541538</id><published>2011-01-11T22:42:00.003Z</published><updated>2011-01-11T22:54:29.859Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-11T22:54:29.859Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CheckBoxList" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="webpart" /><category scheme="http://www.blogger.com/atom/ns#" term="SPListItemCollection" /><category scheme="http://www.blogger.com/atom/ns#" term="reference values" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="CAML" /><category scheme="http://www.blogger.com/atom/ns#" term="Web part" /><category scheme="http://www.blogger.com/atom/ns#" term="lists" /><title>Binding a CheckBoxList object to an ordered Sharepoint list of reference values in a web part (c#)</title><content type="html">&lt;iframe src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;o=1&amp;p=8&amp;l=bpl&amp;asins=0470434007&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="align:left;padding-top:5px;width:131px;height:245px;padding-right:10px;"align="left" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;It's common when creating database applications to use reference tables to provide lookup values.&amp;nbsp; These tables ofter contain a flag that is used to mark a record as no longer available, and an order column that provides a method of putting the values in an order of importantance, perhaps when using them in a drop down list or list of checkboxes.&amp;nbsp; Sharepoint is NOT a database, however there is no reason why good practice such as this cannot be applied to Sharepoint's list model.&lt;br /&gt;
&lt;br /&gt;
In the following example I will show you how to set up a reference list and then use the Sharepoint object model to programmatically access this list and bind it to an control (in this case a Sharepoint CheckBoxList control).&amp;nbsp; Once you understand this, you can use the same method to connect to any reference list and bind it to other objects and controls, such as drop down lists.  This example has been developed for Sharepoint 2007, but should also work for Sharepoint 2010.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Step 1:&amp;nbsp; Set up a reference list&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Create a new list on your Sharepoint site with teh following structure:&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;ID - integer (this is a default field) - this will be used as the unique key (lookup value) used to link this reference filed to other lists&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;Title - string (this is a default field) - this is used to hold the description of the reference field, and will be the value shown in lookups&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: large;"&gt;&lt;span style="font-size: small;"&gt;SortOrder - integer, default 1000 - this can be used to sort the list values in lookups and programmatically using CAML &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Enabled - Yes/No field, default Yes - setting to NO will enable you to filter out these values in views and in programmatic lookups in CAML&lt;/li&gt;
&lt;/ul&gt;You can now enter you reference values into the list, for example here is a list of types of medical record:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_i-bmRB_QqtU/TSzZQ4DVy8I/AAAAAAAAAIY/yPdDB8Y9nDg/s1600/Order-list-cropped.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="287" src="http://2.bp.blogspot.com/_i-bmRB_QqtU/TSzZQ4DVy8I/AAAAAAAAAIY/yPdDB8Y9nDg/s320/Order-list-cropped.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Step 2:&amp;nbsp; Add method to webpart that use CAML to read and order the list&lt;/span&gt;&lt;br /&gt;
Now for the code that reads the Sharepoint list in a structured manner so we can use it in web parts.&amp;nbsp; First, add the following method to your web part: &lt;br /&gt;
&lt;pre class="brush:csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Returns a list collection, ordered using a field in the list called "SortOrder"
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="listName"&amp;gt;The literal string name of the list to query&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;SPListItemCollection&amp;lt;/returns&amp;gt;
private SPListItemCollection ReadOrderedList(string listName)
{
    try
    {
        using (SPWeb configWeb = SPContext.Current.Site.OpenWeb())
        {
            //Get the list
            SPList lookupList = configWeb.Lists[listName];
            // Use CAML to order the list
            SPQuery query = new SPQuery();
            // This CAML where clause searches for only items where the Enabled field is set to "Yes"
            query.Query = "&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name=\"Enabled\" /&amp;gt;&amp;lt;Value Type=\"Integer\"&amp;gt;1&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt; ";
            // This CAML order by claus uses an integer field of "SortOrder"
            query.Query += "&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name=\"SortOrder\" /&amp;gt;&amp;lt;/OrderBy&amp;gt;";
            SPListItemCollection lookupItems = lookupList.GetItems(query);
            return lookupItems;
        }
    }
    catch (Exception ex)
    {
        ErrorTrap("ReadOrderedList: " + ex.Message + Environment.NewLine + ex.StackTrace.ToString());
        throw;
    }
}&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;
This method will return the content of the list in a SPListItemCollection object.  CAML is use to order the list by the "SortOrder" column, and to ignore values that do not have the boolean field "Enabled" set to true.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;Step 3:&amp;nbsp; Bind the list to a control&lt;/span&gt;&lt;br /&gt;
At the class level of your webpart, create the control that you wish to bind to (in this case a CheckBoxList):&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;CheckBoxList myCheckList = new CheckBoxList();
&lt;/pre&gt;&lt;br /&gt;
To bind this control to your Sharpoint list, put this code in the CreateChildControls() method.  Simply replace "My List" with the real name of your list: &lt;br /&gt;
&lt;pre class="brush:csharp"&gt;// Set up the Record Section checkboxes list
    SPListItemCollection dt = ReadOrderedList("My List");
    myCheckList.DataSource = dt;
    myCheckList.DataTextField = "Title";
    myCheckList.DataValueField = "ID";
    myCheckList.DataBind();
&lt;/pre&gt;&lt;br /&gt;
That's it!  You now have a Sharepoint object bound to your Sharepoint list of reference values.&amp;nbsp; When rendered, the output will look something like this:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_i-bmRB_QqtU/TSzcu3SQIOI/AAAAAAAAAIc/9NGCU5ppKeY/s1600/CheckBoxList.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_i-bmRB_QqtU/TSzcu3SQIOI/AAAAAAAAAIc/9NGCU5ppKeY/s1600/CheckBoxList.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Yyou can use the following method to render the CheckBoxList to the web part.&amp;nbsp; This example puts the CheckBoxList in a DIV that fixes the maximum size of the list with a scrollbar.&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;/// &amp;lt;summary&amp;gt;
/// render a list of checkboxes  to the page
/// &amp;lt;/summary&amp;gt;
void RenderCheckBoxes()
{
    try
    {
        // Set up list of checkboxes
        myCheckList.EnableViewState = true;
        myCheckList.CellSpacing = 0;
        myCheckList.CellPadding = 0;

        for (int i = 0; i &amp;lt; myCheckList.Items.Count; i++)
        {
            ListItem li = new ListItem(myCheckList.Items[i].Text, myCheckList.Items[i].Value);
           
            // Set all boxes to selected if not a postback
            if (!Page.IsPostBack)
            {
                myCheckList.Items[i].Selected = true;
            }

        }
        // Give the checklist an ID (can use this in javascript etc)
        myCheckList.ID = "RecordSections";

        //Add controls to web part
        Controls.Add(new LiteralControl(@"&amp;lt;TABLE border='0' bordercolor='red' cellpadding='0' cellspacing='0' valign='top'&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;TR&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;"));
        Controls.Add(new LiteralControl(@"&amp;lt;div class=""ms-frombody""&amp;gt;&amp;lt;b&amp;gt;Record Sections&amp;lt;/b&amp;gt;&amp;lt;/div&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;/TD&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;/TR&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;TR&amp;gt;"));

        Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;\r\n"));
        Controls.Add(new LiteralControl(@"&amp;lt;input type=""hidden"" id=""ScrollPos"" runat=""server""/&amp;gt;"));

        Controls.Add(new LiteralControl(@"&amp;lt;div id='RecordSectionScroll' style=""OVERFLOW: auto; WIDTH: 247px;  TOP: 0px; HEIGHT: 300px"" onscroll=""javascript:document.getElementById('ScrollPos').value = this.scrollTop""&amp;gt; "));

        Controls.Add(myCheckList);
        Controls.Add(new LiteralControl("&amp;lt;/div&amp;gt;&amp;lt;/TD&amp;gt;"));
        Controls.Add(new LiteralControl("&amp;lt;/TR&amp;gt;"));     
        Controls.Add(new LiteralControl("&amp;lt;/TABLE&amp;gt;"));
    }
    catch (Exception ex)
    {
        ErrorTrap("RenderCheckBoxes" + ex.Message + Environment.NewLine + ex.StackTrace.ToString());
    }
}
&lt;/pre&gt;&lt;br /&gt;
Note that I am using literal controls to render the check boxes in a HTML table.  This is pretty horrible and I don't recommend it, but it does work.&lt;br /&gt;
&lt;br /&gt;
Here is the ErrorTrap method.  Note that this is just a simple error handling function and is not required to render a checklist bound to a Sharepoint list, but since it appears in the examples I though I would show you what I do.&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Give an error message
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="myMessage"&amp;gt;&amp;lt;/param&amp;gt;
void ErrorTrap(string myMessage)
{
    Controls.Add(new LiteralControl("&amp;lt;strong&amp;gt;ERROR: " + myMessage.ToString() + "&amp;lt;BR/&amp;gt;&amp;lt;/strong&amp;gt;"));
    ErrorToFile(myMessage);          
}

/// &amp;lt;summary&amp;gt;
/// Write errors to the log file
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="myMessage"&amp;gt;&amp;lt;/param&amp;gt;
void ErrorToFile(string myMessage)
{
    using (StreamWriter sw = new StreamWriter("D:\\SearchErrorLog.txt"))
    {
        DateTime now = new DateTime();
        sw.Write(now.ToString() + ": " + myMessage.ToString());
    }
}
&lt;/pre&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;o=1&amp;p=8&amp;l=bpl&amp;asins=1590594568&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="align:left;padding-top:5px;width:131px;height:245px;padding-right:10px;"align="left" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;iframe src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;o=1&amp;p=8&amp;l=bpl&amp;asins=B0026A6AUG&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" style="align:left;padding-top:5px;width:131px;height:245px;padding-right:10px;"align="left" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-16676474789541538?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ftY9mfkNyNW18rfXqFauVZ0x80w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ftY9mfkNyNW18rfXqFauVZ0x80w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ftY9mfkNyNW18rfXqFauVZ0x80w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ftY9mfkNyNW18rfXqFauVZ0x80w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/vX59-zVRBM8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/16676474789541538/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2011/01/binding-checkboxlist-object-to-ordered.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/16676474789541538?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/16676474789541538?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/vX59-zVRBM8/binding-checkboxlist-object-to-ordered.html" title="Binding a CheckBoxList object to an ordered Sharepoint list of reference values in a web part (c#)" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_i-bmRB_QqtU/TSzZQ4DVy8I/AAAAAAAAAIY/yPdDB8Y9nDg/s72-c/Order-list-cropped.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2011/01/binding-checkboxlist-object-to-ordered.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MHRng6fCp7ImA9Wx9VEEo.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5412011148506116067</id><published>2010-11-16T13:56:00.004Z</published><updated>2011-01-26T20:57:17.614Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-26T20:57:17.614Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="ContentType" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="form" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="Web part" /><title>Render Content Type fields as a form in Sharepoint Web Part  using c#</title><content type="html">In this blog entry I will give you some example code that will render a simple form in a Sharepoint 2007 web part.  The form fields are taken from a pre-defined Sharepoint Content Type.  I struggled to find any examples of this on the net, despite it seeming to me to be a fairly ordinary thing to want to do (after all, if you go to all the trouble of defined your own Content Types to organise your data, surely you would want to use them in your own web parts?).&lt;br /&gt;
&lt;br /&gt;
In order to develop this, I used C# / Visual Studio 2008 and Sharpoint 2007.  This should also work in Visual Studio 2005, although you will have to install the web part manually - Visual Studio 2008 has far tighter links to Sharepoint, meaning debugging and deploying is much easier. It should also work in VS2010 / Sharepoint 2010.&lt;br /&gt;
&lt;br /&gt;
The following method will return a SPContentType object, you only need to pass it a list name and content type name.&amp;nbsp; The SPContentType object can be used later to iterate through its fields in oder to render controls based on the content type's fields.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Returns the content type object
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="listName"&amp;gt;&amp;lt;/param&amp;gt;
/// &amp;lt;param name="contentTypeName"&amp;gt;&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
SPContentType ReadContentType(string listName, string contentTypeName)
{

    //get the web
    this._web = Microsoft.SharePoint.SPContext.Current.Web;

    SPList dirList = this._web.Lists[listName];
    SPContentType contentType = dirList.ContentTypes[contentTypeName];

    //You could simply iterate here like this if you wish, like this:
    //foreach (SPField field in _contentType.Fields)
    //{
    //    string dispName = field.Title;
    //    SPFieldType type = field.Type;
    //    object defaultValue = field.DefaultValue;

    //}

    return contentType;
}
&lt;/pre&gt;&lt;br /&gt;
The following code overrides the "CreateChildControls" Sharepoint method to create our own controls based on the content type.&amp;nbsp; In this example, only text fields and date-times are rendered, but hopefully it straight forward enough for you can see how you could extend this.  Simply change:&amp;nbsp; &lt;br /&gt;
&lt;pre class="brush:csharp"&gt;"Your_List_Name" and "Your_Content_Type_Name" &lt;/pre&gt;to your actual values from your Sharepoint site.&lt;br /&gt;
I use the "LiteralControl" method to render raw HTML on the page to format the form, which feels really nasty but is efective.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;protected override void CreateChildControls()
{
    //Controls.Clear();
    //base.CreateChildControls();

    // Read in the content type for the target list
    SPContentType contentType = ReadContentType("Your_List_Name", "Your_Content_Type_Name");
    
    Controls.Add(new LiteralControl("&amp;lt;TABLE&amp;gt;"));

    foreach (SPField field in contentType.Fields)
    {
        // Ignore hidden or readonly fields
        if (field.Hidden) continue;
        if (field.ReadOnlyField) continue;     

        if (field.Type == SPFieldType.Text)
        {
            string dispName = field.Title;
            string staticName = field.StaticName;
            SPFieldType type = field.Type;
            object defaultValue = field.DefaultValue;

            Controls.Add(new LiteralControl("&amp;lt;TR&amp;gt;"));
            Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;"));
            Label lbl = new Label();
            lbl.Text = dispName;

            Controls.Add(lbl);

            Controls.Add(new LiteralControl("&amp;lt;/TD&amp;gt;"));

            // Textbox
            TextBox tb = new TextBox();
            // I give my controls a unique ID so I can reference them later
            tb.ID = "xx_ctl_xx" + dispName;
            
            if(defaultValue != null)
                tb.Text = defaultValue.ToString();

            Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;"));
            Controls.Add(tb);
            Controls.Add(new LiteralControl("&amp;lt;/TD&amp;gt;"));
            Controls.Add(new LiteralControl("&amp;lt;/TR&amp;gt;"));

        }
        else if (field.Type == SPFieldType.DateTime)
        {
            
            string dispName = field.Title;
            string staticName = field.StaticName;
            SPFieldType type = field.Type;
            object defaultValue = field.DefaultValue;

            Label lbl = new Label();
            lbl.Text = dispName;

            Controls.Add(new LiteralControl("&amp;lt;TR&amp;gt;"));
            Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;"));
            Controls.Add(lbl);
            Controls.Add(new LiteralControl("&amp;lt;/TD&amp;gt;"));

            // Datetime picker
            SPDatePickerControl dtp = new SPDatePickerControl();
            dtp.ID = "xx_ctl_xx" + staticName;
           
            if (defaultValue != null)
                dtp.SelectedDate = defaultValue.ToString();

            Controls.Add(new LiteralControl("&amp;lt;TD&amp;gt;"));
            Controls.Add(dtp);
            
            Controls.Add(new LiteralControl("&amp;lt;/TD&amp;gt;"));
            Controls.Add(new LiteralControl("&amp;lt;/TR&amp;gt;"));
        }       
    }
    Controls.Add(new LiteralControl("&amp;lt;/TABLE&amp;gt;"));

    //In my code, I use the controls to perform a custom search.  The following code plugs in
    //the event handler to do this, based on the values the user puts into the controls rendered above.
    //This blog post will not go into the detail of this so I have commented the following lines out.
    //cmdSearch = new Button();
    //cmdSearch.Text = "Start Search";
    //cmdSearch.Click += new EventHandler(cmdSearch_Click);
    //this.Controls.Add(cmdSearch);

    //lblQueryResult = new Label();                     
    //this.Controls.Add(lblQueryResult);
    
    base.CreateChildControls();
}
&lt;/pre&gt;&lt;br /&gt;
Once deployed, you can add this web part to your site in the normal way using the web front end.&amp;nbsp; Depending on the fields in your content type, it should render something like this (web part highlighted in pink):&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_i-bmRB_QqtU/TOKMwOrtAFI/AAAAAAAAAH4/9fvFEZfBd9A/s1600/ContentTypeRenderedAsForm2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="262" src="http://1.bp.blogspot.com/_i-bmRB_QqtU/TOKMwOrtAFI/AAAAAAAAAH4/9fvFEZfBd9A/s320/ContentTypeRenderedAsForm2.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0972688862&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0672330504&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0735625387&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5412011148506116067?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rcvPiMVfG953VS9B2SKs2gxgRo4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rcvPiMVfG953VS9B2SKs2gxgRo4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rcvPiMVfG953VS9B2SKs2gxgRo4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rcvPiMVfG953VS9B2SKs2gxgRo4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/ODIHo3nuBlg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5412011148506116067/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/11/render-content-type-fields-as-form-in.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5412011148506116067?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5412011148506116067?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/ODIHo3nuBlg/render-content-type-fields-as-form-in.html" title="Render Content Type fields as a form in Sharepoint Web Part  using c#" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_i-bmRB_QqtU/TOKMwOrtAFI/AAAAAAAAAH4/9fvFEZfBd9A/s72-c/ContentTypeRenderedAsForm2.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/11/render-content-type-fields-as-form-in.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkcCQH04fCp7ImA9Wx9bFU0.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-2002294145352807836</id><published>2010-07-08T00:29:00.004+01:00</published><updated>2011-02-24T00:41:01.334Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-24T00:41:01.334Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="column" /><category scheme="http://www.blogger.com/atom/ns#" term="color" /><category scheme="http://www.blogger.com/atom/ns#" term="colour" /><category scheme="http://www.blogger.com/atom/ns#" term="code" /><category scheme="http://www.blogger.com/atom/ns#" term="list" /><category scheme="http://www.blogger.com/atom/ns#" term="RAG" /><category scheme="http://www.blogger.com/atom/ns#" term="Jquery" /><title>Colour code a RAG column in Sharepoint 2007 list view using Jquery</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0596159773&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;I'm a big fan of Microsoft Sharepoint, even though it really annoys me sometimes.  It's amazing that no matter what question a client asks of it, it never can quite answer the question straight out of the box.  However, this is not a problem, because Sharepoint is virtually infinately customisable by a competent programmer with enough time to become emersed in the "Sharepoint Way" and no fear of learning new techniques.&lt;br /&gt;
An example of this came up for me recently when a client requested that a column on a list would be colour coded depending on the value of the data in that column.  The data would be a RAG rating (i.e. a "choice" field containing a set of values that relate to red, amber or green), and therefore it would be nice to colour code the column in eiter red, amber or green to match the rating.  Sharepoint does not give you any easy way of doing this unfortunately.&lt;br /&gt;
&lt;br /&gt;
This is where &lt;a href="http://jquery.com/"&gt;Jquery &lt;/a&gt;comes in.  This terrific library of javascript offers developers a new and consise way of dealing with the internet document object model (DOM).  With it developers can quickly and easily scan the object model of the page returned in the browser, and change the page before it is rendered.  There is far more to it than this of course, but this is the trick I used to colour code the columns.&lt;br /&gt;
&lt;br /&gt;
To colour (color) code a coloumn, follow these steps:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Download the jquery.js library from teh link above, and upload it to your Sharepoint site in a convenient location (I use the Site Documents Collection in my top level publishing site, but anywhere will do)&lt;/li&gt;
&lt;li&gt;Edit the Sharepoint page that the holds the list, and add a Content Editor Web Part (CEWP).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_i-bmRB_QqtU/TDUK6P-Di8I/AAAAAAAAAHY/f4RvnLXXccU/s1600/site-collection-documents.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="233" src="http://3.bp.blogspot.com/_i-bmRB_QqtU/TDUK6P-Di8I/AAAAAAAAAHY/f4RvnLXXccU/s400/site-collection-documents.gif" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Edit the CEWP, choose the "edit source" option, and paste in something like the following code &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_i-bmRB_QqtU/TDUL-2aEdHI/AAAAAAAAAHg/Uite8bF4r-g/s1600/CEWPedit.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/_i-bmRB_QqtU/TDUL-2aEdHI/AAAAAAAAAHg/Uite8bF4r-g/s400/CEWPedit.gif" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;pre class="brush:jscript"&gt;&amp;lt;script type="text/javascript" src="http://&amp;lt;root site&amp;gt;/SiteCollectionDocuments/jquery-1.4.2.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;

$(document).ready(function(){
$(".ms-vb2:contains('&lt;b&gt;1: No Assurance&lt;/b&gt;')").each(function(){
$(this).css("background-color", "&lt;b&gt;#FF0000&lt;/b&gt;");
//$(this).css("filter", "alpha(opacity=50)"); 
});

$(".ms-vb2:contains('&lt;b&gt;2: Limited Assurance&lt;/b&gt;')").each(function(){
$(this).css("background-color", "&lt;b&gt;#FF9900&lt;/b&gt;");
});

$(".ms-vb2:contains('&lt;b&gt;3: Significant Assurance&lt;/b&gt;')").each(function(){
$(this).css("background-color", "&lt;b&gt;#FFFF00&lt;/b&gt;");
});

$(".ms-vb2:contains('&lt;b&gt;4: Full Assurance&lt;/b&gt;')").each(function(){
$(this).css("background-color", "&lt;b&gt;#00CC00&lt;/b&gt;");
});

});
&amp;lt;script&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Note that in this example, the Jquery library is located at: http://&amp;lt;root site&amp;gt;/SiteCollectionDocuments/jquery-1.4.2.js.   Change this to the URL of your own Jquery library.&lt;br /&gt;
&lt;br /&gt;
In my example, the RAG rating column can contain the following values:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;1: No Assurance&amp;nbsp; (RGB #FF0000)&lt;/li&gt;
&lt;li&gt;2: Limited Assurance (RBG #FF9900)&lt;/li&gt;
&lt;li&gt;3: Significant Assurance&amp;nbsp; (RGB #FFFF00)&lt;/li&gt;
&lt;li&gt;4: Full Assurance (RGB #00CC00)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Now to explain what this is actually doing:  "ms-vb2" is the standard Sharepoint site template CSS class that is used to identify columns in a list view web part.&lt;br /&gt;
What this Jquery script is effectively doing is looking for a DOM item with the class "ms-vb2", and in each case that it this&lt;br /&gt;
DOM item contains a specific piece of text ("1: No Assurance", "2: Limited Assurance" etc.), it modifies the CSS of this&lt;br /&gt;
particular section of the DOM to add a "background-color" CSS tag.&lt;br /&gt;
&lt;br /&gt;
Of course your list will have different values, so remember to change the strings in bold to match your own list values!&lt;br /&gt;
The colour codes are standard RGB, so you may find &lt;a href="http://www.science.uva.nl/ict/guides/www/guides/colors/index_en.html"&gt;this RGB table&lt;/a&gt; useful to decide your colours. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Your results will look something like this:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_i-bmRB_QqtU/TDUK0ijnZoI/AAAAAAAAAHQ/2GuyRwTGt6w/s1600/colouredcolumn.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="308" src="http://1.bp.blogspot.com/_i-bmRB_QqtU/TDUK0ijnZoI/AAAAAAAAAHQ/2GuyRwTGt6w/s640/colouredcolumn.gif" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;Best of luck!&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1847199720&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0980576857&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1935182323&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470227796&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-2002294145352807836?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uesYc73Uosx-bMEmGa4J4fjqwdc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uesYc73Uosx-bMEmGa4J4fjqwdc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uesYc73Uosx-bMEmGa4J4fjqwdc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uesYc73Uosx-bMEmGa4J4fjqwdc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/tEeig2yGW8w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/2002294145352807836/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/07/colour-code-single-column-in-sharepoint.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2002294145352807836?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2002294145352807836?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/tEeig2yGW8w/colour-code-single-column-in-sharepoint.html" title="Colour code a RAG column in Sharepoint 2007 list view using Jquery" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_i-bmRB_QqtU/TDUK6P-Di8I/AAAAAAAAAHY/f4RvnLXXccU/s72-c/site-collection-documents.gif" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/07/colour-code-single-column-in-sharepoint.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04BSHc-fSp7ImA9WxFaF0g.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5805078517244344881</id><published>2010-05-11T23:27:00.007+01:00</published><updated>2010-07-22T00:45:59.955+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-22T00:45:59.955+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="RichTextBox" /><category scheme="http://www.blogger.com/atom/ns#" term="VB.Net" /><category scheme="http://www.blogger.com/atom/ns#" term=".net" /><category scheme="http://www.blogger.com/atom/ns#" term="logging" /><category scheme="http://www.blogger.com/atom/ns#" term="color" /><category scheme="http://www.blogger.com/atom/ns#" term="colour" /><category scheme="http://www.blogger.com/atom/ns#" term="Controls" /><title>Write lines to a RichTextBox control in different colours (VB .net example)</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470502215&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;I create a lot of back end "processing" software, for example migration or upgrade tools that process documents as they find them on a server.  As a standard, I tend to write their progress out to a text file, but I also like the program to show me what is happening as it processes files by writing the log file to the screen.  This is particularly useful when debugging the application, but it's also far more satisfying to see something happening on the screen.&lt;br /&gt;
&lt;br /&gt;
In this situation it is nice to write out warnings or non critical errors in different colours in order to attract the eye.&lt;br /&gt;
&lt;br /&gt;
To achieve this, create a &lt;a href="http://msdn.microsoft.com/en-us/library/3tdc88y7.aspx"&gt;RichTextBox&lt;/a&gt; control on your main form (in my example it is called "fInfoBox"), and write to it using the code in the sub routine below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;Sub ShowLog(ByVal qFore as Drawing.Color, ByVal sMesg as string)
   Dim sDispMess As String
   sDispMess = Date.Now()&amp;amp; ": " &amp;amp; sMesg &amp;amp; vbCrLf 

   With fInfoBox 'This is the name of you RichTextBox control on your form
       .SelectionStart = Len(.Text)
       .SelectionBullet = True  ' This shows the line in bulleted form, comment out if not required

       .SelectionColor = qFore
       .SelectedText = sDispMess.ToString()
    End With

    fInfoBox.ScrollToCaret()  ' This scrols to the last line of the text box
End Sub
&lt;/pre&gt;&lt;br /&gt;
To display a message with a font colour of blue, call the routine like this:&lt;br /&gt;
&lt;pre class="brush: vb"&gt;ShowLog(Drawing.Color.Blue, "This message will appear in a font color of blue")
&lt;/pre&gt;For a red message, try this:&lt;br /&gt;
&lt;pre class="brush: vb"&gt;ShowLog(Drawing.Color.Red, "ERROR: This message will display in a font color of red!!")
&lt;/pre&gt;This is a very simple example, but I hope it helps someone get started with this sort of thing and gives you some ideas.&lt;br /&gt;
&lt;br /&gt;
Remember that if you use threading or the backgroundworker class to remove your time consuming processes from the UI (which you should, especially since this is so easy after .Net 2.0), then you will need to use a callback technique for your worker thread to be able to talk to your UI thread.&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=159059892X&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5805078517244344881?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rfmsgzh9j3dNj3usxHKBZGh-6io/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rfmsgzh9j3dNj3usxHKBZGh-6io/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rfmsgzh9j3dNj3usxHKBZGh-6io/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rfmsgzh9j3dNj3usxHKBZGh-6io/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/XLWjMjzw_-I" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5805078517244344881/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/05/write-different-coloured-lines-to.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5805078517244344881?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5805078517244344881?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/XLWjMjzw_-I/write-different-coloured-lines-to.html" title="Write lines to a RichTextBox control in different colours (VB .net example)" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/05/write-different-coloured-lines-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYHSX49cSp7ImA9Wx9aGE0.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-3426175935126809158</id><published>2010-04-21T22:06:00.016+01:00</published><updated>2011-03-11T00:42:18.069Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-11T00:42:18.069Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="GetListCollection" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><title>VBA code to iterate through the results of GetListCollection web service from Sharepoint 2007</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0470127287&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
In  a &lt;a href="http://the-simple-programmer.blogspot.com/2010_03_01_archive.html"&gt;previous post&lt;/a&gt; I discussed how to set meta-data in Sharepoint 2007 directly from VBA.&amp;nbsp; I mentioned that the Microsoft documentation for the Sharepoint web services does not appear to be correct, insofar as you cannot address a Sharepoint "list" in the web service using its name, but rather you are forced to use the GUID.&lt;br /&gt;
&lt;br /&gt;
I have now had to write a function to retrieve the GUID for the list from teh Sharepoint site.&amp;nbsp; This proved to be much harder in practice than I had expected it to be, partly at least because of the problems in working in the VBA IDE with its poor debugging functionality, partly because VBA is a much more limited language than .Net and I have got used to using all the nice constructs such as generics that make life so much easier,&amp;nbsp; and partly because I still find MSXML very "brain" hard to work with.&amp;nbsp; I don't know why I find it so hard, it just always seems that everything ends up being far more complicated than I think it should be.&amp;nbsp; I find the .Net XML model much easier to deal with.&lt;br /&gt;
&lt;br /&gt;
Anyway, after playing about with XSLT and XPATH in order to extract the ID and VersionNumber attributes from the wsm_GetListCollection web service (and failing miserable), I finally decided to just iterate through the nodes and attributes till I found what I wanted.&amp;nbsp; The code below is a simple function that you can call with three parameters:&amp;nbsp; the name of the list that you need the GUID for (sListName),&amp;nbsp; a string variable in which the GUID will be placed (sListID), and an integer that the list version number will be placed (iListVersion).&lt;br /&gt;
&lt;br /&gt;
Note: You may also be interested in this post: &lt;a href="http://the-simple-programmer.blogspot.com/2011/03/vba-code-to-check-in-document-to.html"&gt;VBA code to check in a document to Sharepoint and set meta data&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;Function GetListCollection(ByVal sListName As String, ByRef sListID As String, ByRef iListVersion As Integer)
    ' Class created by toolkit to connect to the Web service
    Dim ws As New clsws_Lists
    ' The collection is returned as an XML node list
    Dim ListCollectionNodeList As MSXML2.IXMLDOMNodeList
    'Root node of the returned list
    Dim nod As MSXML2.IXMLDOMNode
    ' Output string for the XML transformation
    Dim strOutput As String
 
    On Error GoTo GetListCollection_OnError
 
    ' Retrieve the collection of lists
    Set ListCollectionNodeList = ws.wsm_GetListCollection
 
    ' Get the root node from the list
    Set nod = ListCollectionNodeList.Item(0)
 
 
    ' Iterate nodelist to find details for our named list
    Dim bGotNode
    bGotNode = False
 
 
    Dim procNode As MSXML2.IXMLDOMNode
    Dim TitleNodeList As MSXML2.IXMLDOMNodeList
    Dim IDNodeList As MSXML2.IXMLDOMNodeList
    Set TitleNodeList = nod.SelectSingleNode("//Title")
    Set IDNodeList = nod.SelectSingleNode("//ID")
 
    Dim ListNode As MSXML2.IXMLDOMNode
    Dim ListChildNodes As MSXML2.IXMLDOMNode
    Dim oAttr As MSXML2.IXMLDOMAttribute
 
    Dim retID As String
    Dim listVersion As Integer
    Dim ListName As String
 
    ' Iterate through list nodes returned (should only be one)
    For Each ListNode In ListCollectionNodeList
        'Iterate through the child nodes (each one represents a single Sharepoint list)
        For Each ListChildNodes In ListNode.ChildNodes
            'See if we have any attributes (we should have!)
            If ListChildNodes.Attributes.Length &amp;gt; 0 Then
                ' For each list, reset our variables
                retID = ""
                listVersion = 0
 
                ' Iterate through the attributes
                For Each oAttr In ListChildNodes.Attributes
                    Debug.Print "Name= " &amp;amp; oAttr.Name
                    Debug.Print "Value= " &amp;amp; oAttr.nodeTypedValue
 
                    'Look for the ID attribute
                    If oAttr.Name = "ID" Then
                        ' FOund it, so remember it in case this is our list
                        retID = oAttr.nodeTypedValue
                    End If
 
                    ' Look for the "Title" attribute
                    If oAttr.Name = "Title" Then
                        If oAttr.nodeTypedValue = sListName Then
                            ' Found our list, so remember it
                            ListName = oAttr.nodeTypedValue
                            bGotNode = True
                        End If
                    End If
 
                    ' Look for the "Version" attribute
                    If oAttr.Name = "Version" Then
                            ' Found our list, so remember it
                            listVersion = oAttr.nodeTypedValue
                    End If
 
                    ' Once we have found a title, ID and version, break
                    If retID &amp;lt;&amp;gt; "" And listVersion &amp;lt;&amp;gt; 0 And bGotNode = True Then
                       Exit For
                    End If
 
                Next oAttr
            End If
            ' Once we have found the data, break out of iteration
            If bGotNode = True Then
                Exit For
            End If
        Next
    Next
 
    If bGotNode = False Then
        Err.Raise 65000, "", "ERROR: Cannot find list named &amp;lt;" &amp;amp; sListName &amp;amp; "&amp;gt; in Sharepoint site.", "", ""
    End If
 
    sListName = ListName
    sListID = retID
    iListVersion = listVersion
 
    Exit Function
 
GetListCollection_OnError:
    MsgBox ("ERROR: Retrieving list collection from Sharepoint." + vbCrLf + _
           Err.Number + " - " + Err.Description)
End Function
&lt;/pre&gt;&lt;br /&gt;
Remember, you will have to have installed the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=fa36018a-e1cf-48a3-9b35-169d819ecf18&amp;amp;DisplayLang=en"&gt;Microsoft Web Services Toolkit&lt;/a&gt; before this will work, and &lt;a href="http://msdn.microsoft.com/en-us/library/aa192537%28office.11%29.aspx"&gt;add a web reference to your Sharepoint site to your VBA project&lt;/a&gt;.  This has been tested with Office 2003 linking to Sharepoint 2007 and works :).&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0596006780&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-3426175935126809158?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/OmGhqcCoYltx8N3L84aTPwTiGZo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OmGhqcCoYltx8N3L84aTPwTiGZo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/OmGhqcCoYltx8N3L84aTPwTiGZo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/OmGhqcCoYltx8N3L84aTPwTiGZo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/ZDe0Qww-Sw4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/3426175935126809158/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/3426175935126809158?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/3426175935126809158?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/ZDe0Qww-Sw4/vba-code-to-iterate-through-results-of.html" title="VBA code to iterate through the results of GetListCollection web service from Sharepoint 2007" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUAQXo9cSp7ImA9Wx9aGE0.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-332549108872769976</id><published>2010-03-10T23:24:00.009Z</published><updated>2011-03-11T00:44:00.469Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-11T00:44:00.469Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="SOAP" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><category scheme="http://www.blogger.com/atom/ns#" term="updatelist" /><title>Set Sharepoint meta-data from VBA using updatelist web service</title><content type="html">&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1590594568&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;I've been working on a problem trying to integrate a legacy Microsoft Office 2003 VBA application with Sharepoint 2007.  In theory, I should be able to use the SOAP toolkit provided my Microsoft to talk to the Sharepoint (WSS) web services, but in practice there was very little documentation of how to do this, and I could find no resources on the internet aside from the MSDN definitions of the web services, and only a little attached to the SOAP toolkit (available here: &lt;a href="http://msdn.microsoft.com/en-us/library/aa192537%28office.11%29.aspx"&gt;Microsoft Office 2003 Web Services Toolkit&lt;/a&gt; ).&lt;br /&gt;
&lt;br /&gt;
The basic problem I was trying to solve was: how do I set meta-data held on a document in Sharepoint from Office 2003 using VBA? &lt;br /&gt;
&lt;br /&gt;
After much head scratching I finally solved this by making some assumptions based on the MSDN reference documentation, then using the &lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt; tool until I had worked out what I was doing wrong.&amp;nbsp; Fiddler allows you to inspect the HTTP calls and responses that you are issuing/receiving.&amp;nbsp; This is very helpful when debugging web services, and well worth looking into if you are doing anything in this area.&lt;br /&gt;
&lt;br /&gt;
Anyway, through Fiddler I could see the response from the web service, including the error message.&amp;nbsp; This meant that my initial best guess on how to structure the XML was at least nearly correct, because the web service was giving me a proper error message.&amp;nbsp; Eventually I had a properly structured call and everything worked!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember to install the SOAP toolkit before you try this.&amp;nbsp; You will then be able to add this to your VBA project and add a web reference to your project to the WSS Lists.asmx service as you would if your using .Net.&amp;nbsp; This is all explained in the MSDN link above but drop a comment if you would like me to go into more detail.&lt;br /&gt;
&lt;br /&gt;
The actual VBA code used structure the call to the web service looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;'Define a new list service web service class
Dim listws As New clsws_Lists

' Set up the batch command used to set the meta data. 
' Note that FileRef is set to URL of the file you want to change
'ListVersion is from my test site, you may not need that
' First set up DOM document containing fields
Dim xmlDoc As New MSXML2.DOMDocument30
xmlDoc.async = False
Dim xmlText As String
xmlText = "&amp;lt;root&amp;gt;" + _
  "&amp;lt;Batch OnError='Continue' ListVersion='59' PreCalc='TRUE' xmlns=''&amp;gt;" + _
      "&amp;lt;Method ID='1' Cmd='Update'&amp;gt;" + _
        "&amp;lt;Field Name='ID' /&amp;gt;" + _
        "&amp;lt;Field Name='FileRef'&amp;gt;http://myservername:1080/sites/mysite/shared documents/TestWebService.doc&amp;lt;/Field&amp;gt;" + _
        "&amp;lt;Field Name='Title'&amp;gt;Uploaded from VBA&amp;lt;/Field&amp;gt;" + _
        "&amp;lt;Field Name='Surname'&amp;gt;" + sLastName + "&amp;lt;/Field&amp;gt;" + _
        "&amp;lt;Field Name='Forename'&amp;gt;" + sFirstName + "&amp;lt;/Field&amp;gt;" + _
        "&amp;lt;Field Name='Date_x0020_of_x0020_Birth'&amp;gt;" + sDOB + "&amp;lt;/Field&amp;gt;" + _
      "&amp;lt;/Method&amp;gt;" + _
    "&amp;lt;/Batch&amp;gt;" + _
  "&amp;lt;/root&amp;gt;"
xmlDoc.LoadXml (xmlText)

' This is a bit of debug that checks the XML is well formed and show you it if it is. 
If xmlDoc.parseError.ErrorCode &amp;lt;&amp;gt; 0 Then
    Dim myErr
    Set myErr = xmlDoc.parseError
    MsgBox (myErr.reason)
Else
    MsgBox xmlDoc.XML
End If

' Set up IXMLDOMNodeList object
Dim myXMLNodeList As MSXML2.IXMLDOMNodeList
Dim root As MSXML2.IXMLDOMElement
' Now the the XML node list to the batch command we have just constructed above
Set root = xmlDoc.documentElement
Set myXMLNodeList = root.ChildNodes

' Now run the web service to update the meta-data.
' Note that the first parameter is the GUID of the list that holds the data you want to change.  I can't get this to take a list name - it only seems to wrok with a GUID.
Dim updateReturn As IXMLDOMNodeList
Set updateReturn = listws.wsm_UpdateListItems("{B768B024-8B98-4918-990A-ECE34691DBBC}", myXMLNodeList)
&lt;/pre&gt;&lt;br /&gt;
If you need to find out the GUID or ListVersion values for your list, use the "GetListCollection" web service and iterate through the XML it returns:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: vb"&gt;Dim listCollection As IXMLDOMNode
Set listCollection = listws.wsm_GetListCollection
' You can iterate this to find the GUID of our list
&lt;/pre&gt;I can post further examples if anybody wants any.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;*Edit*&lt;/b&gt; - I have written another blog post on how to find the GUID of lists in VBA here: &lt;a href="http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html"&gt;http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html&lt;/a&gt;&lt;br /&gt;
This simple function will return the version number and the GUID of the Sharepoint list from its name. &amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
You may also be interested in teh following post: :&amp;nbsp; &lt;a href="http://the-simple-programmer.blogspot.com/2011/03/vba-code-to-check-in-document-to.html"&gt;VBA code to check in a document to Sharepoint and set meta data&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=0764559036&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1556222238&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-332549108872769976?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/C1EkwDTLKvSz8D-e7MVLd0kG7XA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C1EkwDTLKvSz8D-e7MVLd0kG7XA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/C1EkwDTLKvSz8D-e7MVLd0kG7XA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C1EkwDTLKvSz8D-e7MVLd0kG7XA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/gMOMSVzqdAM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/332549108872769976/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/03/set-sharepoint-meta-data-from-vba-using.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/332549108872769976?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/332549108872769976?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/gMOMSVzqdAM/set-sharepoint-meta-data-from-vba-using.html" title="Set Sharepoint meta-data from VBA using updatelist web service" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>4</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/03/set-sharepoint-meta-data-from-vba-using.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkMERX45eyp7ImA9WxBbFEQ.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-9064940382369777555</id><published>2010-02-21T16:32:00.005Z</published><updated>2010-03-13T16:40:04.023Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-03-13T16:40:04.023Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="MySQL" /><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="integration" /><category scheme="http://www.blogger.com/atom/ns#" term="openquery" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server" /><title>SQL Server - MySQL 4 integration - openquery does not work for tables with datetime values of 0000-00-00</title><content type="html">I have been trying copy the contents of an old MySQL 4.0.12 database to SQL Server 2008 in order to archive its contents.&lt;br /&gt;
&lt;br /&gt;
To archive this, I followed these steps:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Create an database within SQL Server 2008 to hold the data called ARCHIVE_DB. &lt;/li&gt;
&lt;li&gt;Download and install ODBC driver for MySQL (&lt;a href="http://www.mysql.com/downloads/connector/odbc/3.51.html#downloads"&gt;available here&lt;/a&gt;).&amp;nbsp; Note that due to the version of the MySQL database I was unable to use the newer driver (version 5.1.xx), since this requires version 4.1 of MySQL.&lt;/li&gt;
&lt;li&gt;Set up a linked server in SQL Server 2008 using this driver to point to the data source.&amp;nbsp; I called this data source MYSQL_ls.&lt;/li&gt;
&lt;li&gt;I can now select data from this data source using the "openquery" TSQL syntax, eg:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: sql"&gt;SELECT *
FROM openquery([NADT-SQLHOST], 'select * from webdb.episode')
&lt;/pre&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;I can extend this query using the TSQL "INTO" clause, which will build the SQL table from the source data, eg:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: sql"&gt;SELECT * INTO ARCHIVE_DB
FROM openquery([MYSQL_ls], 'select * from mydatabase.mytable')
&lt;/pre&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;In theory the above will copy all the data from the MySQL database table called &lt;mytable&gt; (in the MySQL database called &lt;mydatabase&gt;) into the SQL Server table &lt;mytable&gt; (SQL Server database &lt;archive_db&gt;).&amp;nbsp; I do not have to create the table schema, this will be created automatically by the INTO clause.&amp;nbsp;&amp;nbsp;&lt;/archive_db&gt;&lt;/mytable&gt;&lt;/mydatabase&gt;&lt;/mytable&gt;&lt;/li&gt;
&lt;li&gt;I can now create an SSIS package that loops through the tables in the MySQL database and runs the SQL statement show in number 5 against each table.&amp;nbsp; This should in theory copy each table across. &lt;/li&gt;
&lt;/ol&gt;This technique works very well until you come to tables that include datetime values.&lt;br /&gt;
&lt;br /&gt;
MySQL allows datetime values in the format of "0000-00-00", which is the equivalent of a NULL date in SQL server.&amp;nbsp; Unfortunately the "Select * Into From Openquery..." trick above does not deal with this situation, and you will recieve a version of the following error:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: sql"&gt;Msg 7342, Level 16, State 1, Line 4
An unexpected NULL value was returned for column "[MSDASQL].enddate" from OLE DB provider "MSDASQL" for linked server "MYSQL_ls". This column cannot be NULL.
&lt;/pre&gt;&lt;br /&gt;
This error is caused by using "openquery".&amp;nbsp; Fortunately there is a very easy work around for this:&amp;nbsp; where tables have datetimes in "0000-00-00" format, you must use an SSIS data flow task to copy the information, rather than the "openquery" described above:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Set the data pump source to the MySQL table pointed to in the Linked server and click on "preview" and you will notice that it can return data.&amp;nbsp; This is not possible by running a query in the SQL Management studio, so clearly we are getting somewhere.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt; Now set the data pump target to "&lt;new table=""&gt;" and click on "Mappings" and you will notice that each column in the source table will be mapped to an identically named table in the destination table.&lt;/new&gt;&lt;/li&gt;
&lt;li&gt;Save the data pump and run.&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
If you run this data flow, the data will be copied across without reporing the datetime mismatch error.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-9064940382369777555?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HiOFj5TZ6vxgvXaNOMsnjTMtfPM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HiOFj5TZ6vxgvXaNOMsnjTMtfPM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HiOFj5TZ6vxgvXaNOMsnjTMtfPM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HiOFj5TZ6vxgvXaNOMsnjTMtfPM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/jKm5LC5stag" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/9064940382369777555/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/02/sql-server-mysql-4-integration.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/9064940382369777555?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/9064940382369777555?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/jKm5LC5stag/sql-server-mysql-4-integration.html" title="SQL Server - MySQL 4 integration - openquery does not work for tables with datetime values of 0000-00-00" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/02/sql-server-mysql-4-integration.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8BRXo5eyp7ImA9WxBVFEk.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5851913905572762056</id><published>2010-02-17T21:40:00.001Z</published><updated>2010-02-17T21:40:54.423Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-17T21:40:54.423Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SSIS" /><category scheme="http://www.blogger.com/atom/ns#" term="variable" /><category scheme="http://www.blogger.com/atom/ns#" term="table name" /><category scheme="http://www.blogger.com/atom/ns#" term="SQL" /><title>Use a variable as a table name in an SSIS Execute SQL Task</title><content type="html">I spent quite a while today trying to build an SSIS package that iterated through a dataset that contained a set of table names usign a for-each container, then run a piece of SQL against each table.&lt;br /&gt;
&lt;br /&gt;
Setting up the for-each loop was relatively simple, but I couldn't get the Execute SQL task to run a simple query of the type:&lt;br /&gt;
&lt;pre class="brush: sql"&gt;Select count(*) from @table
&lt;/pre&gt;Where @table is the name of the parameter generated from the for each loop.&lt;br /&gt;
&lt;br /&gt;
It appears that this is not possible in SSIS.&amp;nbsp; Eventually I found a solution:&amp;nbsp; use another variable to store the SQL statement and set up the SQL task to use this variable as its input source.&lt;br /&gt;
&lt;br /&gt;
Assuming that the input parameter is already set up and called [User::TableName],&amp;nbsp; then the steps to achive this are:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Set up a new variable (say called "SQLStatement"), make this a string type.&lt;/li&gt;
&lt;li&gt;In the properties box of the paremeter, Set EvaluateAsExpression to True&lt;/li&gt;
&lt;li&gt;In the properties box of the paremeter, click on the elipses (...) of the "Expression" property to build an expression.&amp;nbsp; Type in the SQL you need and drag the variable you want to use from the "variables" tree. &lt;/li&gt;
&lt;li&gt;Escape you SQL in this expression wwithin quotation marks.&amp;nbsp; e.g. the count statement above would look like:&lt;/li&gt;

&lt;pre class="brush: sql"&gt;"Select count(*) from " + @[User:TableName]&amp;nbsp;&lt;/pre&gt;

&lt;li&gt;&amp;nbsp;You can use the "Evaluate expression" button to make sure that this evaluates as real SQL.&amp;nbsp; If you are using a "for-each" container then you may want to give your [User::TableName] variable a sensible default value in order to see the results of the evaluated expression in a format you could use for testing.&lt;/li&gt;
&lt;li&gt;Drag an "Execute SQL Task" object into your control flow and open its properties page&lt;/li&gt;
&lt;li&gt;Set the "SQL Source Type" property to "Variable" to tell it that the SQL will come from a variable, rather from a typed in SQL statement.&lt;/li&gt;
&lt;li&gt;Set the "SourceVariable" property to the name of the variable you created in step 1 (in this example it would be "SQLStatement".&lt;/li&gt;
&lt;/ol&gt;That's it! &amp;nbsp; &lt;br /&gt;
&lt;ol&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5851913905572762056?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gnVDCbJWuaZ__sWgi65pySBzH6Q/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gnVDCbJWuaZ__sWgi65pySBzH6Q/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gnVDCbJWuaZ__sWgi65pySBzH6Q/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gnVDCbJWuaZ__sWgi65pySBzH6Q/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/1ftMQcTulgg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5851913905572762056/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/02/use-variable-as-table-name-in-ssis.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5851913905572762056?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5851913905572762056?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/1ftMQcTulgg/use-variable-as-table-name-in-ssis.html" title="Use a variable as a table name in an SSIS Execute SQL Task" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/02/use-variable-as-table-name-in-ssis.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcBQnc8eCp7ImA9WxBWGEw.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-7164356618749424065</id><published>2010-02-08T21:41:00.006Z</published><updated>2010-02-10T14:27:33.970Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-10T14:27:33.970Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="blogger" /><category scheme="http://www.blogger.com/atom/ns#" term="syntax highlighting" /><title>Blogger.com code syntax highlighting, or always remember to save your code before you start playing around with it!</title><content type="html">I've decided to re-vamp the look of this blog to give it more width and make the code fragments easier to read.  I hope you like the new look!&lt;br /&gt;
&lt;br /&gt;
When doing this I made one of the oldest mistakes in the programmer's book: I didn't save my work!&lt;br /&gt;
&lt;br /&gt;
This meant I had to add all the site specific code to render the code in syntax-highlighted format, and add Google analytics tracking code back into the HTML, which whilst not the worst job in the world, did take me some time to remember what I had done. &lt;b&gt; &lt;i&gt;REMEMBER TO SAVE YOUR WORK!&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This does give me the opportunity to thank the author of the fabulous syntax highlighter for Blogger.com that I have used, which can be found here: &lt;a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter"&gt;http://alexgorbatchev.com/wiki/SyntaxHighlighter&lt;/a&gt;.  Thank you very much Alex, it's a superb bit of code!&lt;br /&gt;
&lt;br /&gt;
The code I used to enable the nifty highlighter for C# should be pasted into the HEAD section of your blog:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: html"&gt;&amp;lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/&amp;gt;
&amp;lt;link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;!-- add brushes here --&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type='text/javascript'&amp;gt;
  SyntaxHighlighter.config.bloggerMode = true;
  SyntaxHighlighter.all();
&amp;lt;/script&amp;gt;

&lt;/pre&gt;&lt;br /&gt;
To use it, make sure that the code you want to display has been HTML escaped (which can be done using the utility available here: &lt;a href="http://www.string-functions.com/htmlencode.aspx"&gt;http://www.string-functions.com/htmlencode.aspx&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Now, to use this, just paste your escaped code into your blog and wrap it in the following HTML tags:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;&amp;lt;pre class=&amp;quot;brush:csharp&amp;quot;&amp;gt;
   ...your code here...
&amp;lt;/pre&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Note that this will work for C Sharp code.  For other types of code highlighting, simply change the brush type in the &amp;lt;pre&amp;gt; tag, and make sure the appropriate brush is included in the list of brish types defined in the code above in the "!-- add brushes here --" section.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-7164356618749424065?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/YY8a5h6yi-3szcsUhb8qfHntKc4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YY8a5h6yi-3szcsUhb8qfHntKc4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/YY8a5h6yi-3szcsUhb8qfHntKc4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/YY8a5h6yi-3szcsUhb8qfHntKc4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/__R-wZxeeUA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/7164356618749424065/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/02/bloggercom-code-syntax-highlighting-or.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7164356618749424065?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7164356618749424065?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/__R-wZxeeUA/bloggercom-code-syntax-highlighting-or.html" title="Blogger.com code syntax highlighting, or always remember to save your code before you start playing around with it!" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/02/bloggercom-code-syntax-highlighting-or.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUUCQno7eyp7ImA9WxFbFU4.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-7869670876499469143</id><published>2010-01-22T00:29:00.013Z</published><updated>2010-07-07T22:14:23.403+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-07T22:14:23.403+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="BackgroundWorker" /><category scheme="http://www.blogger.com/atom/ns#" term="Arrays" /><title>Manage c# threads easily using an array of BackgroundWorker class objects</title><content type="html">I recently built a piece of software that processed files on a server.&amp;nbsp; There are hundreds of thousands of files, so this took a long time to run through, so I decided to use threads in order to process multiple files at once.&lt;br /&gt;
&lt;br /&gt;
I wanted to be able to manage these threads, and be able to control how many threads I used by a programmatic variable so I could use more or less threads depending upon the power of the machine the process would be run on, and I could try different numbers of threads and benchmark the results to find the optimum number of threads.&lt;br /&gt;
&lt;br /&gt;
The solution I came up with uses an array of .Net 2.0 BackgroundWorker class objects, initialised at run time to the size of the integer variable "maxThreads".&lt;br /&gt;
&lt;br /&gt;
The following code sets up the variables and initialises the array:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;static int maxThreads = 20;  //Make bigger or smaller, it's up to you!
private BackgroundWorker[] threadArray = new BackgroundWorker[maxThreads];
static int _numberBackGroundThreads --;  //Just for fun

// Set up the BackgroundWorker object by 
// attaching event handlers. 
private void InitializeBackgoundWorkers()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int f = 0; f &amp;lt; maxThreads; f++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f] = new BackgroundWorker();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f].DoWork +=
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new DoWorkEventHandler(backgroundWorkerFiles_DoWork);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f].RunWorkerCompleted +=
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new RunWorkerCompletedEventHandler(backgroundWorkerFiles_RunWorkerCompleted);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f].ProgressChanged +=
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new ProgressChangedEventHandler(backgroundWorkerFiles_ProgressChanged);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f].WorkerReportsProgress = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; threadArray[f].WorkerSupportsCancellation = true;

&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}

&lt;/pre&gt;&lt;br /&gt;
Each BackgroundWorker class has three event handlers assigned to it:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;backgroundWorkerFiles_DoWork - This delegate method is used to run the process&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;backgroundWorkerFiles_RunWorkerCompleted - this delegate method is called once the "DoWork" method has completed&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;backgroundWorkerFiles_ProgressChanged - this delegate method is used to pass information back to the calling thread, for example to report progress to the GUI thread.&lt;/li&gt;
&lt;/ol&gt;This delegate methods are discussed at length on the MSDN site so I wont go into them in detail here other than to show you this simple code outline:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;private void backgroundWorkerFiles_DoWork(object sender, DoWorkEventArgs e)
{
    //Just for fun - increment the count of the number of threads we are currently using.  Can show this number in the GUI.
    _numberBackGroundThreads --;
    
    // Get argument from DoWorkEventArgs argument.  Can use any type here with cast
    int myProcessArguments = (int)e.Argument;

    // "ProcessFile" is the name of my method that does the main work.  Replace with your own method!  
    // Can return reulsts from this method, i.e. a status (OK, FAIL etc)
    e.Result = ProcessFile(myProcessArgument);
}

private void backgroundWorkerFiles_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    // Use this method to report progress to GUI
}

private void backgroundWorkerFiles_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    // First, handle the case where an exception was thrown.
    if (e.Error != null)
    {
        MessageBox.Show(e.Error.Message);
    }

    // For fun - print out the result of the ProcessFile() method.
    debug.print = e.Result.ToString();

    // Just for fun - decrement the count of threads
    _numberBackGroundThreads --;
}
&lt;/pre&gt;&lt;br /&gt;
OK now comes the fun part.  The following code shows a loop thorugh a large number of items.  Rather than run ProcessFile() for each item in the loop in turn, we instead choose an unused thread to run it in.  This allows the loop to step onto the next item, which also is allocated an empty thread.   &lt;br /&gt;
&lt;pre class="brush:csharp"&gt;// Some process with many iterations
for(int f = 0; f &amp;lt; 100000; f++)
{

    //Use the thread array to process ech iteration
    //choose the first unused thread.
    bool fileProcessed = false;
    while (!fileProcessed)
    {
        for (int threadNum = 0; threadNum &amp;lt; maxThreads; threadNum++)
        {
            if (!threadArray[threadNum].IsBusy)
            {   // This thread is available
                Debug.Print("Starting thread: " + threadNum);
        
                //Call the "RunWorkerAsync()" method of the thread.  
                //This will call the delegate method "backgroundWorkerFiles_DoWork()" method defined above.  
                //The parameter passed (the loop counter "f") will be available through the delegate's argument "e" through the ".Argument" property.
                threadArray[threadNum].RunWorkerAsync(f);
                fileProcessed = true;
                break;
            }
        }
        //If all threads are being used, sleep awhile before checking again
        if (!fileProcessed)
        {
            Thread.Sleep(50);
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
Using this technique, it's eay to create 2, 10, or even 100 threads to process each loop iteration asychronously, which speeds up execution time enormously.&amp;nbsp; Simply change the value of "maxThreads" to whatever you need!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-7869670876499469143?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BGPcWAxrxQzrbKd7KWiqZsNdZY8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BGPcWAxrxQzrbKd7KWiqZsNdZY8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BGPcWAxrxQzrbKd7KWiqZsNdZY8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BGPcWAxrxQzrbKd7KWiqZsNdZY8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/2c8tLdr9L8Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/7869670876499469143/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/01/manage-thread-creation-using-array-of.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7869670876499469143?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/7869670876499469143?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/2c8tLdr9L8Y/manage-thread-creation-using-array-of.html" title="Manage c# threads easily using an array of BackgroundWorker class objects" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>5</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/01/manage-thread-creation-using-array-of.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUBR3k5eyp7ImA9WxBRF04.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-2179806788698215834</id><published>2010-01-06T00:04:00.000Z</published><updated>2010-01-06T00:04:16.723Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-06T00:04:16.723Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="define" /><category scheme="http://www.blogger.com/atom/ns#" term="URI" /><category scheme="http://www.blogger.com/atom/ns#" term="difference" /><category scheme="http://www.blogger.com/atom/ns#" term="URL" /><title>What is the difference between  a URI and a URL?</title><content type="html">If you get confused between URLs (Uniform Resource Locators) and URIs (Uniform Resource Identifiers), then simply think of a URL as a special type of URI used to point to resources on the WWW. &lt;br /&gt;
&lt;br /&gt;
The term "URL" is now deprecated (a term meaning marked for removal in computing circles), and the term "URI" is now the accepted term in computer science. However with the rise of the internet "URL" has become entrenched within the English language and is used and understood widely among non computer scientists. It's not possible for any group of individuals to deprecate words (although plenty have tried...) so "URL" will probably long outlive its technical definition.&lt;br /&gt;
&lt;br /&gt;
At the end of the day, I expect that if you should use the term "URL" when you really mean "URI" everybody will know what you mean!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-2179806788698215834?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/bcEfSW_RlrlrsjJSVEpiw7pXThM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bcEfSW_RlrlrsjJSVEpiw7pXThM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/bcEfSW_RlrlrsjJSVEpiw7pXThM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/bcEfSW_RlrlrsjJSVEpiw7pXThM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/jSN_mjPav-E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/2179806788698215834/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/01/what-is-difference-between-uri-and-url.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2179806788698215834?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2179806788698215834?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/jSN_mjPav-E/what-is-difference-between-uri-and-url.html" title="What is the difference between  a URI and a URL?" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/01/what-is-difference-between-uri-and-url.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak8MRHY6eip7ImA9WxBWFkk.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-3859714791926357004</id><published>2010-01-05T22:00:00.001Z</published><updated>2010-02-08T17:08:05.812Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-02-08T17:08:05.812Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="strip" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term=".net" /><category scheme="http://www.blogger.com/atom/ns#" term="URI" /><category scheme="http://www.blogger.com/atom/ns#" term="segments" /><category scheme="http://www.blogger.com/atom/ns#" term="URL" /><title>Strip and manipulate a URL by breaking it into segments (.NET 2.0)</title><content type="html">I recently required a method that would take a string that contain a URL (href), and another string that contained a root section of this URL (root), and return a string that contained the remained of the URL (i.e. the section of href that remained once the root had been removed). &lt;br /&gt;
&lt;br /&gt;
To make matters more complicated, the href parameter could have some unusual features.&amp;nbsp; Because this URL was pointing to content created by users in a Content Management System (CMS), some segments of the URL contained trailing or leading white space (segments being the bits of the URL between the slashes).&amp;nbsp;&amp;nbsp; This whitespace is fine in the CMS system, but my method must strip this whitespace to return a canonical URL.&lt;br /&gt;
&lt;br /&gt;
Fortunately .Net 2.0 onwards provides us with the URI class.&amp;nbsp; This has lots of fabulous methods and properties, but in this example I shall use it to:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt; turn the parameter strings "root" and "href" URLs into canonical URIs&lt;/li&gt;
&lt;li&gt; break down the "href" parameter into segments,&amp;nbsp;&lt;/li&gt;
&lt;li&gt;ignore the segments that exist in the "root" parameter,&lt;/li&gt;
&lt;li&gt;strip leading and trailing whitespace from the remaining segments &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;return the canonicalised section of the URL&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;string GetRootStrippedURI(string root, string href)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; Uri fileUri = new Uri(Uri.UnescapeDataString(href));
&amp;nbsp;&amp;nbsp;&amp;nbsp; Uri rootUri = new Uri(Uri.UnescapeDataString(root));

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create the return string from the root
&amp;nbsp;&amp;nbsp;&amp;nbsp; string strippedExtension = "";

&amp;nbsp;&amp;nbsp;&amp;nbsp; // Loop through segments not in the root and clean them up
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = rootUri.Segments.Length; i &amp;lt; fileUri.Segments.Length - 1; i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strippedExtension += fileUri.Segments[i].TrimEnd().TrimStart();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return strippedExtension;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-3859714791926357004?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/C5DLurl9mKEtmiqt-LtUPY_VTQs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C5DLurl9mKEtmiqt-LtUPY_VTQs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/C5DLurl9mKEtmiqt-LtUPY_VTQs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C5DLurl9mKEtmiqt-LtUPY_VTQs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/tDTvrfiz0J8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/3859714791926357004/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2010/01/strip-and-manipulate-url-by-breaking-it.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/3859714791926357004?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/3859714791926357004?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/tDTvrfiz0J8/strip-and-manipulate-url-by-breaking-it.html" title="Strip and manipulate a URL by breaking it into segments (.NET 2.0)" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2010/01/strip-and-manipulate-url-by-breaking-it.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkEBQXc5eip7ImA9Wx9aFk0.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-2344739926031128485</id><published>2009-12-15T22:12:00.002Z</published><updated>2011-03-08T16:10:50.922Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-08T16:10:50.922Z</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="example" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="Timer" /><category scheme="http://www.blogger.com/atom/ns#" term="stopwatch" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><title>A c# timer stopwatch class to help analyse lengthy program execution</title><content type="html">I have recently been developing a piece of software that uses the old Microsoft COM Interop technology to walk through a Sharepoint 2001 folder structure.  I found that this was working pretty slowly, but by the time I came around to do anything about it the code had got fairly complicated and it wasn't clear where the bottleneck was occuring.&lt;br /&gt;
&lt;br /&gt;
To help understand the problem I created this simple static timer class:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;class Timer
    {
        static public DateTime timeStart;
        static public DateTime timeEnd;
        static public bool debugTimer = true;  //Switch to false to turn off timing messages
 
        public  Timer()
        {
        }
 
        static public void TimerStart(string msg)
        {
            if (! debugTimer) return;
            timeStart = DateTime.Now;
            Console.WriteLine(&amp;quot;TIMER: &amp;quot; + msg + &amp;quot; BEGUN: &amp;quot; + timeStart.ToString(), true);
        }
 
        static public void TimerEnd()
        {
            if (!debugTimer) return;
            timeEnd = DateTime.Now;
            TimeSpan totalTime = new TimeSpan();
            totalTime = timeEnd.Subtract(timeStart);
 
            Console.WriteLine(&amp;quot;TIMER END: &amp;quot; + timeEnd.ToString() + &amp;quot; Total time: &amp;quot; + totalTime.Milliseconds, true);
        }
    }
&lt;/pre&gt;&lt;br /&gt;
In order to use this in your code, simply copy the class and put the following lines around whatever process you wish to monitor:&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;Timer.TimerStart("Beginning timer");
    //...
    //do lenghtly process
    //...
    Timer.TimerEnd();
&lt;/pre&gt;&lt;br /&gt;
This will give a nice message, with the time elapsed in milliseconds.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-2344739926031128485?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Jy_NHI-69Rpt3G1tAxylwLWt_yM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Jy_NHI-69Rpt3G1tAxylwLWt_yM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Jy_NHI-69Rpt3G1tAxylwLWt_yM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Jy_NHI-69Rpt3G1tAxylwLWt_yM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/q1N09oqEcDs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/2344739926031128485/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2009/12/c-timer-class-to-analyse-program.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2344739926031128485?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/2344739926031128485?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/q1N09oqEcDs/c-timer-class-to-analyse-program.html" title="A c# timer stopwatch class to help analyse lengthy program execution" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2009/12/c-timer-class-to-analyse-program.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEcDSX87fCp7ImA9WxFaF0g.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-5357391573597524067</id><published>2009-11-27T19:06:00.007Z</published><updated>2010-07-22T00:47:58.104+01:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-22T00:47:58.104+01:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="fields" /><category scheme="http://www.blogger.com/atom/ns#" term="sharepoint" /><category scheme="http://www.blogger.com/atom/ns#" term="runtime" /><category scheme="http://www.blogger.com/atom/ns#" term="web services" /><category scheme="http://www.blogger.com/atom/ns#" term="c#" /><category scheme="http://www.blogger.com/atom/ns#" term="updatelist" /><title>Creating Sharepoint list fields on the fly with web services</title><content type="html">I've recently been trying to create Sharepoint 2007 list fields on the fly using the Lists.UpdateLists() method described here:&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/lists.lists.updatelist.aspx"&gt;http://msdn.microsoft.com/en-us/library/lists.lists.updatelist.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately, after modifying the sample code to my needs, a SOAP exception kept getting thrown: "NodeType 'Element' is not an valid type":&lt;br /&gt;
&lt;br /&gt;
&amp;lt;errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/"&amp;gt;'Element' is an invalid XmlNodeType. Line 1, position 10.&amp;lt;/errorstring&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Using Visual Studio 2005 to debug,&amp;nbsp; I have been unable to work out what the problem was.&amp;nbsp; The CAML query built in the webservice to create the field must be incorrect, but the innerXML of the CAML query (I was only using the "updateFields" node) looked fine.&amp;nbsp; Clearly the problem was elsewhere in the call, but is not clear to me how the call is constructed once the parameters are passed to the web service.&lt;br /&gt;
&lt;br /&gt;
SOAP does not seem to me to give a huge amount of debugging information when a call fails.&amp;nbsp; When I create my own web services, I can use VS to step through them and get lots of debug information, but I haven't been able to work out how to do this with the MS DLLs yet. &lt;br /&gt;
&lt;br /&gt;
Anyway, I eventually solved this problem by going back to the example and creating another copy of the example Microsoft code with minimal changes in order to point the call at my webservice.&amp;nbsp; This proved to work OK, although it did create two sample fields (Field1 and Field2) that I cannot remove using the Sharepoint IE front end!.&amp;nbsp; I suspect this is becuase they are created as required fields.&lt;br /&gt;
&lt;br /&gt;
By making minimal iterative changes, I finally managed to create the following c# method which successfully creates the fields on the fly, and even gives them an appropriate Sharepoint type.&lt;br /&gt;
&lt;br /&gt;
(Please note this code looks better in IE than Firefox which is not wrapping the lines - click on "View Plain" to view or copy in Firefox)&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:csharp"&gt;public bool CreateNewField(ListInfo listInfo, string fieldName, object fieldValue)
{
    bool canCreateField = true;
    try
    {

                //ListsService.Lists listService = new ListsService.Lists();
                //listService.Credentials= System.Net.CredentialCache.DefaultCredentials;
                //NOTE: I have already instatiated my connection (listService) and the GUID of the list (listInfo.listName)

                XmlNode ndList = listService.GetList(listInfo.listName);
                XmlNode ndVersion = ndList.Attributes["Version"];

                XmlDocument xmlDoc = new System.Xml.XmlDocument();

               

                XmlNode ndNewFields = xmlDoc.CreateNode(XmlNodeType.Element,
                    "Fields", "");
                XmlNode ndUpdateFields = xmlDoc.CreateNode(XmlNodeType.Element,
                    "Fields", "");

               
                
                // Field types
                if(fieldValue.GetType() == Type.GetType("System.String"))
                {
                    ndNewFields.InnerXml = @"&amp;lt;Method ID='1'&amp;gt;" +
                   "&amp;lt;Field Type='Text' DisplayName='" + fieldName + "' Required='FALSE' FromBaseType='FALSE' Description='Generated Field'/&amp;gt;" +
                   "&amp;lt;/Method&amp;gt;";
                }
                else if (fieldValue.GetType() == Type.GetType("System.Int") || 
                         fieldValue.GetType() == Type.GetType("System.UInt16") ||
                    fieldValue.GetType() == Type.GetType("System.UInt32") ||
                    fieldValue.GetType() == Type.GetType("System.UInt64")
                    )
                {
                    ndNewFields.InnerXml = @"&amp;lt;Method ID='1'&amp;gt;" +
                  "&amp;lt;Field Type='Integer' DisplayName='" + fieldName + "' Required='FALSE' FromBaseType='FALSE' Description='Generated Field'/&amp;gt;" +
                  "&amp;lt;/Method&amp;gt;";
                }
                else if (fieldValue.GetType() == Type.GetType("System.Double"))
                {
                    ndNewFields.InnerXml = @"&amp;lt;Method ID='1'&amp;gt;" +
                  "&amp;lt;Field Type='Number' DisplayName='" + fieldName + "' Required='FALSE' FromBaseType='FALSE' Description='Generated Field'/&amp;gt;" +
                  "&amp;lt;/Method&amp;gt;";
                }
                else if (fieldValue.GetType() == Type.GetType("System.Date"))
                {
                    ndNewFields.InnerXml = @"&amp;lt;Method ID='1'&amp;gt;" +
                  "&amp;lt;Field Type='DateTime' DisplayName='" + fieldName + "' Required='FALSE' FromBaseType='FALSE' Description='Generated Field'/&amp;gt;" +
                  "&amp;lt;/Method&amp;gt;";
                }
                else if (fieldValue.GetType() == Type.GetType("System.Array"))
                {
                    ndNewFields.InnerXml = @"&amp;lt;Method ID='1'&amp;gt;" +
                  "&amp;lt;Field Type='Text' DisplayName='" + fieldName + "' Required='FALSE' FromBaseType='FALSE' Description='Generated Field'/&amp;gt;" +
                  "&amp;lt;/Method&amp;gt;";
                }
                else
                {   // Data type not handled - skip field
                    //Logger is my helper class - Remove from your code
                    Logger.LogMessageToFile("WARNING: Undefined field &amp;lt;" + fieldName + "&amp;gt; has an unhandled data type of: " + fieldValue.GetType().ToString() + "\r\n" +
                        "This field cannot be created");
                    canMigrateField = false;

                }
                Type myType = fieldValue.GetType();
                
                if (canCreateField)
                {
                    //NOTE: You need to use the GUID in the listname field.  I have this pre-populated in the listInfo.ListName class
                    XmlNode ndReturn =
                     listService.UpdateList(listInfo.listName,
                     null, ndNewFields, null, null,
                     ndVersion.Value);


             Logger.LogMessageToFile("NEW FIELD &amp;lt;" + fieldName + "&amp;gt; Created successfully.\r\n");
        }

    }

    catch (Exception ex)
    {
        Logger.LogMessageToFile("Message:\n" + ex.Message + "\nStackTrace:\n" + 
            ex.StackTrace);
        Logger.PopupMessage();
    }

    if (canCreateField) return true;
    else return false;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;iframe align="left" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="http://rcm.amazon.com/e/cm?t=thesim06-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=bpl&amp;amp;asins=1590594568&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;m=amazon&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" style="height: 245px; padding-right: 10px; padding-top: 5px; width: 131px;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;span style="font-family: Times New Roman,serif; font-size: small;"&gt;&lt;span style="font-family: Courier New,monospace; font-size: x-small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-5357391573597524067?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/P3RfOrJWE4vn4t27QE7FbjxCbqU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P3RfOrJWE4vn4t27QE7FbjxCbqU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/P3RfOrJWE4vn4t27QE7FbjxCbqU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P3RfOrJWE4vn4t27QE7FbjxCbqU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/bkgcMiejl9c" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/5357391573597524067/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2009/11/creating-sharepoint-list-fields-on-fly.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5357391573597524067?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/5357391573597524067?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/bkgcMiejl9c/creating-sharepoint-list-fields-on-fly.html" title="Creating Sharepoint list fields on the fly with web services" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2009/11/creating-sharepoint-list-fields-on-fly.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck4MSX88eyp7ImA9Wx9bGEg.&quot;"><id>tag:blogger.com,1999:blog-7799238193115123636.post-4264910895227371371</id><published>2009-09-12T13:24:00.057+01:00</published><updated>2011-02-27T23:56:28.173Z</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-27T23:56:28.173Z</app:edited><title>Blog Archive</title><content type="html">&lt;form action="/search" id="searchthis" method="get" style="display: inline;"&gt;&lt;input id="search-box" name="q" size="25" type="text" /&gt; &lt;input id="search-btn" type="submit" value="Search" /&gt; &lt;/form&gt;&lt;br /&gt;
&lt;div style="float: left; width: 90%;"&gt;&lt;a href="http://the-simple-programmer.blogspot.com/2011/02/deploy-visual-studio-2008-vsto-add-in.html"&gt;Deploy Office 2003 VSTO add in to All Users using Visual Studio 2008&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2011/01/sharepoint-2007-batch-update-example.html"&gt;Sharepoint 2007 Batch Update example using web services and CAML&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2011/01/binding-checkboxlist-object-to-ordered.html"&gt;Binding a CheckBoxList object to an ordered Sharepoint list of reference values in a web part (c#)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/11/render-content-type-fields-as-form-in.html"&gt;Render Content Type fields as a form in Sharepoint Web Part using c#&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/07/colour-code-single-column-in-sharepoint.html"&gt;Colour code a single column in Sharepoint 2007 list view using Jquery&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/05/write-different-coloured-lines-to.html"&gt;Write lines to a RichTextBox control in different colours (VB .net example)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/04/vba-code-to-iterate-through-results-of.html"&gt;VBA code to iterate through the results of GetListCollection web service from Sharepoint 2007&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/03/set-sharepoint-meta-data-from-vba-using.html"&gt;Set Sharepoint meta-data from VBA using updatelist web service&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/02/sql-server-mysql-4-integration.html"&gt;SQL Server - MySQL 4 integration - openquery does not work for tables with datetime values of 0000-00-00&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/02/use-variable-as-table-name-in-ssis.html"&gt;Use a variable as a table name in an SSIS Execute SQL Task&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/02/bloggercom-code-syntax-highlighting-or.html"&gt;Blogger.com code syntax highlighting, or always remember to save your code before you start playing around with it!&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/01/manage-thread-creation-using-array-of.html"&gt;Manage c# threads easily using an array of BackgroundWorker class objects&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/01/what-is-difference-between-uri-and-url.html"&gt;What is the difference between a URI and a URL?&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2010/01/strip-and-manipulate-url-by-breaking-it.html"&gt;Strip and manipulate a URL by breaking it into segments (.NET 2.0)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2009/12/c-timer-class-to-analyse-program.html"&gt;A c# timer class to help analyse lengthy program execution&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://the-simple-programmer.blogspot.com/2009/11/creating-sharepoint-list-fields-on-fly.html"&gt;Creating Sharepoint list fields on the fly with web services&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7799238193115123636-4264910895227371371?l=the-simple-programmer.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vbCVFuX6wO9om6zHrvBtWA5-GLw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vbCVFuX6wO9om6zHrvBtWA5-GLw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vbCVFuX6wO9om6zHrvBtWA5-GLw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vbCVFuX6wO9om6zHrvBtWA5-GLw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheSimpleProgrammer/~4/3aS1E9zs-FI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://the-simple-programmer.blogspot.com/feeds/4264910895227371371/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://the-simple-programmer.blogspot.com/2009/09/blog-archive.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/4264910895227371371?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7799238193115123636/posts/default/4264910895227371371?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TheSimpleProgrammer/~3/3aS1E9zs-FI/blog-archive.html" title="Blog Archive" /><author><name>Iain</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://the-simple-programmer.blogspot.com/2009/09/blog-archive.html</feedburner:origLink></entry></feed>

