<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>SharePoint 2007</title>
        <link>http://geekswithblogs.net/socasanta/category/6495.aspx</link>
        <description>SharePoint 2007 and related technologies: InfoPath, Forms Server, Business Data Catalog, etc.</description>
        <language>en-US</language>
        <copyright>Michael Awai</copyright>
        <managingEditor>Nospamsocasanta@nc.rr.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Uploading files to WSS 3.0 document libraries using HTTP PUT and Lists.asmx</title>
            <link>http://geekswithblogs.net/socasanta/archive/2007/07/09/113809.aspx</link>
            <description>&lt;p&gt;
Uploading a file to a Windows SharePoint Services 3.0 document library from external applications can be done in 2 steps using a combination of HTTP PUT and the Lists Web service. 
	
&lt;/p&gt;
&lt;p&gt;
Firstly, for the HTTP PUT side of things, check out:
&lt;a href="http://blogs.msdn.com/rohitpuri/archive/2007/04/10/upload-download-file-to-from-wss-document-library-using-dav.aspx"&gt;
http://blogs.msdn.com/rohitpuri/archive/2007/04/10/upload-download-file-to-from-wss-document-library-using-dav.aspx&lt;/a&gt; 
.  In the code to follow, I use a variation of Rohit's helper class that 
takes a byte[].&lt;/p&gt;
&lt;p&gt;
Secondly, use the Lists Web service UpdateListItems() method to do the update.  
But how do we get the ID from the HTTP PUT?  Turns out you don't need it.  
Providing the FileRef field is enough.  For example, if you uploaded the 
file to &lt;a href="http://mycompany/hr/Documents/bonus.xls"&gt;http://mycompany/hr/Documents/bonus.xls&lt;/a&gt;, 
that's exactly what you'd put in FileRef, as shown below.&lt;/p&gt;
&lt;pre&gt;        public static string UploadFile(string url, string listName, byte[] document, 
                               List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; fileProperties)
        {
            string s = DAVHelper.UploadFile(url, document);
            if(s != "success")
                throw new Exception("File upload to: " + url + " failed.");

            // Update the attributes
            string updateRes = UpdateFileAttributes(url, listName, fileProperties);
            return updateRes;
	}

&lt;/pre&gt;
&lt;pre&gt;        public static string UpdateFileAttributes(string fileUrl, string listName, 
                                List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; fileProperties)
        {
            WssLists.ListsSoapClient listService 
                = new WssLists.ListsSoapClient("ListsSoap");
            listService.ClientCredentials.Windows.AllowedImpersonationLevel 
                = System.Security.Principal.TokenImpersonationLevel.Delegation;

            // Note that when building the Method fields, the field named ID
            // is required, although in this case we can and will leave it empty.
	    // (Concatenated empty string is just for visuals ;)
            StringBuilder sb = new StringBuilder();
            sb.Append("&amp;lt;Method ID='1' Cmd='Update'&amp;gt;");
            sb.Append("  &amp;lt;Field Name='ID'/&amp;gt;" + "" + "&amp;lt;/Field&amp;gt;");
            sb.Append("  &amp;lt;Field Name='FileRef'&amp;gt;" + fileUrl + "&amp;lt;/Field&amp;gt;");

	    // This is what the loop is basically doing:
            // sb.Append("  &amp;lt;Field Name='CustomColumn1'&amp;gt;" + "Some value" + "&amp;lt;/Field&amp;gt;");
            for (int i = 0; i &amp;lt; fileProperties.Count; i++)
            {
                sb.Append("  &amp;lt;Field Name='" + fileProperties[i].Key + "'&amp;gt;" + 
                           Convert.ToString(fileProperties[i].Value) + "&amp;lt;/Field&amp;gt;");
            }

            sb.Append("&amp;lt;/Method&amp;gt;");

            XmlDocument xmlDoc = new System.Xml.XmlDocument();
            System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

            elBatch.SetAttribute("OnError", "Continue");
            elBatch.SetAttribute("PreCalc", "TRUE"); 
            elBatch.SetAttribute("ListVersion", "0"); 

            elBatch.InnerXml = sb.ToString();

	    // Do the update
            XmlNode ndReturn = listService.UpdateListItems(listName, elBatch);

            return ndReturn.OuterXml;
        }&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113809"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113809" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/socasanta/aggbug/113809.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michael Awai</dc:creator>
            <guid>http://geekswithblogs.net/socasanta/archive/2007/07/09/113809.aspx</guid>
            <pubDate>Tue, 10 Jul 2007 00:09:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/socasanta/comments/113809.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/socasanta/archive/2007/07/09/113809.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/socasanta/comments/commentRss/113809.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/socasanta/services/trackbacks/113809.aspx</trackback:ping>
        </item>
        <item>
            <title>Calling WSS 3.0 Web Services from WCF clients</title>
            <link>http://geekswithblogs.net/socasanta/archive/2007/07/06/113725.aspx</link>
            <description>&lt;p&gt;Having just gone through this, I thought I'd share the basic procedure when calling WSS 3.0 Web services such as lists.asmx and views.asmx from a WCF client.  As you may know, the exceptions returned by the WSS Web services are terse.  Hopefully, this post will help someone trying to avoid those in their own project.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 - Add a Service Reference to the WCF service you want to call (Duh)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Note that I included the "?wsdl".  If you don't VS will be redirected to /_vti_bin/Lists.asmx.  That doesn't matter from a service client code generation standpoint, just that the WCF endpoint addresses in App.config will need to be changed as they'll be pointing to the wrong URL, and none of the lists and other objects in your site will be found by the Web services.    &lt;/p&gt;
&lt;p&gt;&lt;img height="216" alt="" width="530" src="/images/geekswithblogs_net/socasanta/AddReference(1).JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2 - Modify the App.Config file to change the security binding configuration used by the client&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the basicHttpBinding section, replace:&lt;/p&gt;
&lt;p class="style1"&gt;&amp;lt;security mode="None"&amp;gt; &lt;br /&gt;
    &amp;lt;transport clientCredentialType="None" &lt;br /&gt;
               proxyCredentialType="None" realm="" /&amp;gt; &lt;br /&gt;
    &amp;lt;message clientCredentialType="UserName" algorithmSuite="Default" /&amp;gt; &lt;br /&gt;
&amp;lt;/security&amp;gt; &lt;/p&gt;
&lt;p&gt;With:&lt;/p&gt;
&lt;p class="style1"&gt;&amp;lt;security mode="TransportCredentialOnly"&amp;gt; &lt;br /&gt;
    &amp;lt;transport clientCredentialType="Ntlm" /&amp;gt; &lt;br /&gt;
&amp;lt;/security&amp;gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3 - Allow the Web service to impersonate the user&lt;/strong&gt;&lt;/p&gt;
&lt;p class="style2"&gt;WssList.ListsSoapClient listService = new WssList.ListsSoapClient("ListsSoap"); &lt;br /&gt;
listService.ClientCredentials.Windows.AllowedImpersonationLevel &lt;br /&gt;
    = System.Security.Principal.TokenImpersonationLevel.Delegation; &lt;br /&gt;
&lt;br /&gt;
XmlElement elem = listService.GetListCollection(); &lt;/p&gt;
&lt;p class="style2"&gt; &lt;/p&gt;
&lt;p class="style2"&gt;End transmission... &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113725"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=113725" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/socasanta/aggbug/113725.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michael Awai</dc:creator>
            <guid>http://geekswithblogs.net/socasanta/archive/2007/07/06/113725.aspx</guid>
            <pubDate>Fri, 06 Jul 2007 14:47:39 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/socasanta/comments/113725.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/socasanta/archive/2007/07/06/113725.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/socasanta/comments/commentRss/113725.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/socasanta/services/trackbacks/113725.aspx</trackback:ping>
        </item>
    </channel>
</rss>