简体   繁体   中英

Sharepoint List Items Query

How i can query sharepoint list items using soap in c#? Code that should query data will be placed on one host (sharepoint 2007, .net 2.0). List located on another host (Sharepoint 2010). As far as I know, I can not use for this purpose SPSite, SPWeb..

using(SPSite site = new SPSite("http://hostname/...")) {
  using(SPWeb web = site.OpenWeb()) {
     ...

Can anyone give me an example of how this can be done? Tnx!

To integrate between two different sharepoint instances you have to use the sharepoint web services.

  1. In your project create a web reference to the following url: http://sharepointserver/_vti_bin/lists.asmx

  2. Create a connection to the web service:

     var client = new SharePointWebServices.Lists { Credentials = new NetworkCredential("username", "password") }; var xmlDoc = new XmlDocument(); var viewFields = xmlDoc.CreateElement("ViewFields"); viewFields.InnerXml = "<FieldRef Name=\\"ows_FIELD YOU WISH TO RETRIEVE\\" />"; var listGuid = ConfigurationManager.AppSettings["GUID_OF_LIST"]; XmlNode listItems = client.GetListItems(listGuid, null, null, viewFields, null, null, null); 
  3. Now you have received your collection. simply iterate through the xmlDoc retrieved from the webservice. I do this like this:

     foreach (XmlNode node in listItems) { if (node.Name == "rs:data") { for (int f = 0; f < node.ChildNodes.Count; f++) { if (node.ChildNodes[f].Name == "z:row") { var xmlAttributeCollection = node.ChildNodes[f].Attributes; if (xmlAttributeCollection != null) { string listItem = xmlAttributeCollection["ows_ows_FIELD YOU WISH TO RETRIEVE"].Value; } } } } } 

You can use SharePoint soap web services . Or if you are getting data from SharePoint 2010 you can use its rest api .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM