WebService UpdateListItems subsite?
Hello,
Please bear with me.
I am trying to add an entry to a subsites calendar, but it will only add it to the main sites calendar. I have tried a number of different changes to fix my code but it seems to only run the web service mehtod against the main site not the subsite. I have tried to split up the problem into sections in order to explain things better, (my english is not the best)
first of all here is the setup of the server
http://moss <- main site
http://moss/dpi <- subsite
I have added a web reference to my C#2.0
http://moss/dpi/_vti_bin/Lists.asmx <- Web service location?
My Code Error Message
<Result ID="1,New" xmlns="http://schemas.microsoft.com/sharepoint/soap/"><ErrorCode>0x81020026</ErrorCode><ErrorText>The list that is referenced here no longer exists.</ErrorText></Result>
I have tried the following
changing the Web Reference of the webservice to http://moss/sites/dpi/_vti_bin/Lists.asmx (still did not work)
call the UpdateListItems method using "Calendar" instead of using the calendar's GUID, but this only added the item to the main sites calendar.
I have also renamed the calendar, changing its title. this did not work
I have listed all the lists using the GetListCollection() method, where it listed all the lists avalible to the main site not the subsite. (I can post this code if required)
also tried listing all the subsites, where my subsite is found correctly
and this is the code
//opens a template update XML document. Assembly a = Assembly.GetEntryAssembly(); XmlDocument doc = new XmlDocument(); FileStream fs = File.Open(Path.GetDirectoryName(a.Location) + "\\CalDoc.xml", FileMode.Open);doc.Load(fs);
fs.Close();
fs.Dispose();
XmlElement rootNode = doc.DocumentElement;//Alters the XML to contain the required information
rootNode.SelectSingleNode(
"/Batch/Method/Field[@Name='Title']").InnerXml = "Dave Day";rootNode.SelectSingleNode(
"/Batch/Method/Field[@Name='Location']").InnerXml = "Location";rootNode.SelectSingleNode(
"/Batch/Method/Field[@Name='Description']").InnerXml = "Description";rootNode.SelectSingleNode("/Batch/Method/Field[@Name='EventDate']").InnerXml = string.Format("{0}T{1}Z", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddMinutes(10).ToString("HH:mm
s"));rootNode.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']").InnerXml = string.Format("{0}T{1}Z", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddHours(1).ToString("HH:mm
s"));//rootNode.SelectSingleNode("/Batch/Method/Field[@Name='fAllDayEvent']").Value = "0";
Console.WriteLine(doc.OuterXml);//Calendar's Name, its GUID
string CalGuid = "{1CC831B0-AE1B-4170-AE43-1337A908C2EB}";//Create an instance of the webservice
banmossdemo.
Lists l = new testAddCalSP.banmossdemo.Lists();l.Credentials = System.Net.
CredentialCache.DefaultCredentials;//call the method
XmlNode node1 = l.UpdateListItems(CalGuid, rootNode);//display the result into a textbox
txtResult.Text =
""; StringBuilder sb = new StringBuilder(); foreach (XmlNode node in node1.ChildNodes){
sb.AppendLine(node.OuterXml);
}
txtResult.Text = sb.ToString();
contents of the CalDoc.xml
<?
xml version="1.0" encoding="utf-8" ?><
Batch><
Method ID="1" Cmd="New"><
Field Name="Title" /><
Field Name="Location" /><
Field Name="Description" /><
Field Name="EventDate" /><
Field Name="EndDate" /><
Field Name="fAllDayEvent" /></
Method></
Batch>many thanks
bones
解答
- Well, in case you haven't solved it yet, I did see somewhere that if you are trying to use UpdateListItems on a list in a subsite you need to append ?wsdl to the url of asmx.
My problem was a bit different as I was trying to access this via a vbs script, but I was able to solve my issue none-the-less.
Creating a new list item using vbscript and Sharepoint WebServices.
I'm including my code as there aren't any thorough examples out on the internets. I based my solution on something from Ian Morrish so I am giving credit where credit is due. I hope someone finds this useful.
Sub AddListItem(site, listGUID, itemTitle)
strEndPointURL = "http://moss" + site + "/_vti_bin/Lists.asmx"
strSoapAction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
Set objSOAPConnector = CreateObject("MSOSOAP.HttpConnector30")
with objSOAPConnector
.Property("EndPointURL") = strEndPointURL
.Property("SoapAction") = strSoapAction
.Connect
End With
Set objSOAPSerializer = CreateObject("MSOSoap.SoapSerializer30")
with objSOAPSerializer
.Init(objSOAPConnector.InputStream)
.startEnvelope()
.startBody()
.StartElement "UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "listName", "http://schemas.microsoft.com/sharepoint/soap/"
.WriteString(listGUID)
.EndElement()
.StartElement "updates","http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "Batch"
.SoapAttribute "ListName", ,listGUID
.SoapAttribute "OnError", ,"Continue"
.StartElement "Method"
.SoapAttribute "ID", ,"1"
.SoapAttribute "Cmd", ,"New"
.StartElement "Field"
.SoapAttribute "Name", ,"Title"
.WriteString(itemTitle)
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.endBody()
.endEnvelope()
End With
objSOAPConnector.EndMessage()
Set objResponseReader = CreateObject("MSOSOAP.SoapReader30")
objResponseReader.Load(objSOAPConnector.OutputStream)
Wscript.echo objResponseReader.Body.xml
End Sub
所有回覆
- I'm having the same problem. Have you solved it?
- Well, in case you haven't solved it yet, I did see somewhere that if you are trying to use UpdateListItems on a list in a subsite you need to append ?wsdl to the url of asmx.
My problem was a bit different as I was trying to access this via a vbs script, but I was able to solve my issue none-the-less.
Creating a new list item using vbscript and Sharepoint WebServices.
I'm including my code as there aren't any thorough examples out on the internets. I based my solution on something from Ian Morrish so I am giving credit where credit is due. I hope someone finds this useful.
Sub AddListItem(site, listGUID, itemTitle)
strEndPointURL = "http://moss" + site + "/_vti_bin/Lists.asmx"
strSoapAction="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems"
Set objSOAPConnector = CreateObject("MSOSOAP.HttpConnector30")
with objSOAPConnector
.Property("EndPointURL") = strEndPointURL
.Property("SoapAction") = strSoapAction
.Connect
End With
Set objSOAPSerializer = CreateObject("MSOSoap.SoapSerializer30")
with objSOAPSerializer
.Init(objSOAPConnector.InputStream)
.startEnvelope()
.startBody()
.StartElement "UpdateListItems", "http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "listName", "http://schemas.microsoft.com/sharepoint/soap/"
.WriteString(listGUID)
.EndElement()
.StartElement "updates","http://schemas.microsoft.com/sharepoint/soap/"
.StartElement "Batch"
.SoapAttribute "ListName", ,listGUID
.SoapAttribute "OnError", ,"Continue"
.StartElement "Method"
.SoapAttribute "ID", ,"1"
.SoapAttribute "Cmd", ,"New"
.StartElement "Field"
.SoapAttribute "Name", ,"Title"
.WriteString(itemTitle)
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.EndElement()
.endBody()
.endEnvelope()
End With
objSOAPConnector.EndMessage()
Set objResponseReader = CreateObject("MSOSOAP.SoapReader30")
objResponseReader.Load(objSOAPConnector.OutputStream)
Wscript.echo objResponseReader.Body.xml
End Sub I'm having the same issue as dbones. I've tried the same solutions, but so far none have worked.
I've also tried appending ?wsdl to the asmx url, but to no avail. I'm not 100% sure, but I beleive the wsdl is used to print out the XML schema for the web service.
Has anyone found a solution to this issue yet?
In case anyone else is having the same problem the solution is to change the Url property of the web service.
I was able to update lists under http://moss just fine, but when I tried to edit a list under http://moss/subweb the code always failed to find the list. I tried updating the web reference and the app.config file to point to http://moss/subweb/_vti_bin/lists.asmx, but this still failed.
I noticed that even after these updates, if I checked the Url property of the web service while the code was running, it was still set to http://moss/_vti_bin/lists.asmx somehow. To fix it, I specifically set the Url property of the web service to http://moss/subweb/_vti_bin/lists.asmx during run time. Below is the code:
SharePoint.
Lists ListService = new SharePoint.Lists();ListService.Credentials = System.Net.
CredentialCache.DefaultCredentials;ListService.Url =
"https://moss/subweb/_vti_bin/Lists.asmx";I have updated the URL property at runtime as recommended and I am still having the same problem. Anymore ideas?
- Hello, for subsites you must use WebID.
This is example how to get web using webpat (example http://sharepointserver/subsite/):
http://www.sharepoint-tips.com/2007/02/how-to-use-getlistitems-web-service.html - it does work when you set the URL at runtime. This is definietly a bug in my opinion. I have set the correct URL when selecting the web service and also made sure that the URL was correct in the app.config file but when i looked at the URL during runtime, it is without the subweb. string strData = string.Format("<Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='Title'>{0}</Field><Field Name='Description'>{1}</Field></Method>", title, description);
Lists.
Lists lists = new ComsolEJob.Lists.Lists();lists.Url =
"http://moss/hr/_vti_bin/lists.asmx"; ///lists.Credentials = System.Net.
CredentialCache.DefaultCredentials; XmlDocument doc = new XmlDocument(); XmlElement el = doc.CreateElement("Batch");el.SetAttribute(
"OnError", "Continue");el.SetAttribute(
"ListVersion", "0");el.SetAttribute(
"ViewName", string.Empty);el.InnerXml = strData;
//{3AD79943-A03C-4B98-979B-65B13B5C6FAC}
XmlNode ndReturn = lists.UpdateListItems("{3AD79943-A03C-4B98-979B-65B13B5C6FAC}", el);
Ouaes Jamali - I have to create a new subfolder under
_siteUrl + "/Corporate/procurement/frame agreement/price list/"
what I do is the following:
1 Lists.Lists listService = new Lists.Lists(); 2 listService.Url = _siteUrl + "/Corporate/procurement/frame agreement/price list/_vti_bin/Lists.asmx"; 3 listService.Credentials = GetCredentials(); 4 5 6 String CreateFolder = "<Method ID=\"1\" Cmd=\"New\"><Field Name=\"ID\">New</Field><Field Name=\"FSObjType\">1</Field><Field Name=\"BaseName\">newFolderName</Field></Method>"; 7 8 9 XmlDocument xmlDoc = new System.Xml.XmlDocument(); 10 11 System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); 12 13 elBatch.SetAttribute("RootFolder", "/Corporate/procurement/frame agreement/price list"); 14 elBatch.SetAttribute("OnError", "Continue"); 15 elBatch.SetAttribute("ListVersion", "1"); 16 elBatch.SetAttribute("ViewName", ""); 17 18 elBatch.InnerXml = CreateFolder; 19 20 XmlNode ndReturn = listService.UpdateListItems(_ListID, elBatch); 21
I'm setting the webservice Url to _siteUrl + "/Corporate/procurement/frame agreement/price list/_vti_bin/Lists.asmx" instead of _siteUrl + "_vti_bin/Lists.asmx" because doing this I get an errory saying that the list couldn't be found..
I tried both not setting rootFolder and putting the whole url in <Field Name=\"BaseName\"> tag but I keep getting the same result:
The operation failed because an unexpected error occurred. (Result Code: 0x80070005)
Please help!
- Hi:
I´ve had the same issue, try using this "\" in the Name: RootFolder/SubFolder, put /Corporate/procurement/frame agreement/price list/newFolderName instead of just newFolderName
something like this:
String CreateFolder = "<Method ID=\"1\" Cmd=\"New\"><Field Name=\"ID\">New</Field><Field Name=\"FSObjType\">1</Field><Field Name=\"BaseName\">/Corporate/procurement/frame agreement/price list/newFolderName</Field></Method>";
regards
Roberto Castro Vexler
- 已提議為解答Roberto Castro Vexler _ 2009年3月9日 下午 12:33

