MSDN > 論壇首頁 > SharePoint - Development and Programming > How to specify particular MOSS site using Lists.GetListItems?
發問發問
 

已答覆How to specify particular MOSS site using Lists.GetListItems?

  • Friday, 2 February, 2007 3:07NicerGuy123123123 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    This must be a stupid question since I can't find any answers out there:

    How should I specify the location of the list (document library) used in Lists.GetListItems?

    Even though all MOSS sites have a _vti_bin/Lists.asmx, I'm assuming I should always use the generic http://servername/_vti_bin/Lists.asmx to connect since adding sites as a web reference would require hard-coding.  Also, if I try the hard-coding method, I still can't figure it out.  I'm also assuming that Document Libraries are lists too and can be accessed this way.

    All the examples suggest just the list name:

    listService.GetListItems(
         "Our Documents",
         null,
         ndQuery,
         ndViewFields,
         null,
         ndQueryOptions,
         null);

    I've tried this with every combination of hard-coded web references and list full URLs but I always get "List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user." SoapException.

    Please help me out.

解答

  • Friday, 2 February, 2007 6:26Ishai Sagi[MOSS MVP]MVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    you cant use null....

    And you do need the site ID

    The following sample code shows how to use the web service, and also a sample function that uses the SiteData web service to get the site url. Please note that i hard coded the site url in the function, but you would do better to get the url of the site you are using with the lists web service.

     

    ListsWebService.Lists listsWS = new ListsWebService.Lists();

    listsWS.UseDefaultCredentials = true;

    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

    doc.LoadXml ("<Document><Query /><ViewFields /><QueryOptions /></Document>");

    System.Xml.XmlNode listQuery = doc.SelectSingleNode("//Query");

    System.Xml.XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");

    System.Xml.XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");

    Guid g = GetWebID();

    System.Xml.XmlNode items= listsWS.GetListItems("Activities", string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions,g.ToString() );

     

    private Guid GetWebID()

    {

    SiteDataWebService.SiteData siteDataWS = new SiteDataWebService.SiteData();

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

    SiteDataWebService._sWebMetadata webMetaData;

    SiteDataWebService._sWebWithTime[] arrWebWithTime;

    SiteDataWebService._sListWithTime[] arrListWithTime;

    SiteDataWebService._sFPUrl[] arrUrls;

    string roles; string[] roleUsers; string[] roleGroups;

    string url = siteDataWS.Url;

    siteDataWS.Url = "http://myserver/_vti_bin/sitedata.asmx";

    uint i = siteDataWS.GetWeb(out webMetaData, out arrWebWithTime, out arrListWithTime, out arrUrls, out roles, out roleUsers, out roleGroups);

    Guid g = new Guid(webMetaData.WebID);

    return g;

    }

所有回覆

  • Friday, 2 February, 2007 6:26Ishai Sagi[MOSS MVP]MVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    you cant use null....

    And you do need the site ID

    The following sample code shows how to use the web service, and also a sample function that uses the SiteData web service to get the site url. Please note that i hard coded the site url in the function, but you would do better to get the url of the site you are using with the lists web service.

     

    ListsWebService.Lists listsWS = new ListsWebService.Lists();

    listsWS.UseDefaultCredentials = true;

    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

    doc.LoadXml ("<Document><Query /><ViewFields /><QueryOptions /></Document>");

    System.Xml.XmlNode listQuery = doc.SelectSingleNode("//Query");

    System.Xml.XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");

    System.Xml.XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");

    Guid g = GetWebID();

    System.Xml.XmlNode items= listsWS.GetListItems("Activities", string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions,g.ToString() );

     

    private Guid GetWebID()

    {

    SiteDataWebService.SiteData siteDataWS = new SiteDataWebService.SiteData();

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

    SiteDataWebService._sWebMetadata webMetaData;

    SiteDataWebService._sWebWithTime[] arrWebWithTime;

    SiteDataWebService._sListWithTime[] arrListWithTime;

    SiteDataWebService._sFPUrl[] arrUrls;

    string roles; string[] roleUsers; string[] roleGroups;

    string url = siteDataWS.Url;

    siteDataWS.Url = "http://myserver/_vti_bin/sitedata.asmx";

    uint i = siteDataWS.GetWeb(out webMetaData, out arrWebWithTime, out arrListWithTime, out arrUrls, out roles, out roleUsers, out roleGroups);

    Guid g = new Guid(webMetaData.WebID);

    return g;

    }

  • Monday, 5 February, 2007 3:04NicerGuy123123123 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

     

    Thanks, dude.  That was a super helpful response.  Difficult to get started into the arena armed only with (yet to be completed, IMHO) MOSS msdn reference.

  • Monday, 4 June, 2007 11:11Fbrum 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hello!

    Sorry, but i believe the answer it's right in front of me, but I don't get it!
    I'm getting an error with SiteDataWebService, ListsOnLocalhost and Sharepoint_Unit_Tests

    For what does this stands for? How to I declare it?

    I'm trying to use getListItems with infopath, but I'm having problems with the definitions of the arguments. So I'm trying to do directly with code.

    But I think that the Microsoft is failing with documentation. It as been impossible to get the arguments right, and it should be so simple. Instead I'm getting vagues SoapServerException!

  • Monday, 4 June, 2007 22:31Ishai Sagi[MOSS MVP]MVP, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    First, it would be polite of you to start a new thread and ask the question in full there, with the code you are trying to use.

    I suspect you didnt add a referance to the web service in your project. In visual studio you need to right click the project and select "add web referance" which would then allow you to put in the link to the web service you want to use.

  • Tuesday, 5 June, 2007 9:04Fbrum 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Sorry! I was getting a little frustrated with InfoPath!
    About the code, it is exactly the one posted here!

    Your suspicions was right, but I already got there. I found it in a msdn blog site.
    My problem now it is another, that I'm trying to decipher.

    Thanks allot for your response Smile

  • Friday, 15 June, 2007 11:56Hitesh Chauhan 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

     

     

    Hi,

     

               how can i use sitedata/webs.asmx to get the logged on user mysite quota detail as we have to two different server one is for mysite and another one is for other sharepoint site. please help me with sample code, if you can.

     

    Thanks & Regards,

    Hitesh chauhan