A1VBCode Forums

Getting values from Sharepoint lists using Web Service


http://www.a1vbcode.com/vbforums/Topic28070.aspx

By Mobius - 8/21/2009

All,



I'm trying to develop my own version of the project that can be found here:



http://www.codeproject.com/KB/sharepoint/SharePointListWebService.aspx



Below is the code, similar to what he's posted, for pulling list items from our MOSS calendar.



mosslists.ListslistService=newmosslists.Lists();



//SharePointWebServicesrequireauthentication

listService.Credentials=System.Net.CredentialCache.DefaultCredentials;



StringnewIssueTitle="Programmaticallyaddedissue";

StringlistGUID="{5B62B9F4-F0CA-4CC5-9753-87A5EB129E3C}";

StringactiveItemViewGUID="{52CDD743-D45B-4548-A521-AA1C7DED4B24}";



stringstrBatch=

""+

String.Format("{0}",newIssueTitle)+

"";



XmlDocumentxmlDoc=newSystem.Xml.XmlDocument();

System.Xml.XmlElementelBatch=xmlDoc.CreateElement("Batch");

elBatch.SetAttribute("OnError","Continue");

elBatch.SetAttribute("ViewName",activeItemViewGUID);

elBatch.InnerXml=strBatch;

XmlNodendReturn=listService.UpdateListItems(listGUID,elBatch);







I'm getting an error on that last line:



XmlNodendReturn=listService.UpdateListItems(listGUID,elBatch);







The error message is as follows:

Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.



Looked at the return packet from the server, and I noticed that the innertext of the error was as follows:

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)



Also, I retrieved the GUIDs you see in the above code by using the utility available here:

http://blogs.msdn.com/ronalus/archive/2007/09/08/a-little-guid-picker.aspx



And in my google quests, most answers revolved around making sure the Web Service reference is added to the MOSS subsite, not the root site. I want to say now, that I've been careful to attach to the correct site.



EDIT: Mark's Syntax Highlighter took all or most of the spaces out of my code. Try to ignore that, I'm compiling just fine, no code syntax errors. Wink
By Mobius - 8/25/2009

Ha! After taking all that time to make sure you all knew I specified the subsite.....I found the problem.



Adding the web reference by navigating to the /_vti_bin/Lists.asmx page DOES NOT mean that this site will be the site that the queries are run on. You still have to set the URL property of the "Lists" variable I created first. Assuming that "mosslists" is the name of the web reference I just created, the following code creates a "list" object, then sets the URL property of that object:



            mosslists.Lists lists = new mosslists.Lists();

            lists.Url = "http:///_vti_bin/Lists.asmx";




So after all that talk about already setting the URL.....I didn't end up finishing the job. Hope this helps those of you that fall into the same trap. Tongue