2010-06-08 7 views
1

이전에 웹 서비스를 통해 셰어 포인트와 개체에 액세스하는 것에 관한 많은 질문을 살펴 봤는데 Lists 인터페이스를 통해 작업에 액세스 할 수 있다는 확신이 들었습니다.웹 서비스를 통해 Sharepoint 작업에 액세스하고 있습니까?

누구든지 나를 확인해 주실 수 있습니까?

또한 누구나이 예제를 가지고 있다면 매우 감사 할 것입니다. 저는 Sharepoint 직원이 아니지만 작업 객체를 검색하기 위해 인스턴스에 연결해야합니다.

답변

4

가 [http://[server-url]/_vti_bin/lists.asmx]

는 아래와 같은 새로운 클래스를 생성은 SharePoint 목록 웹 서비스 에 web reference 추가하기 Visual Studio 및 C#

를 사용하여 코드 솔루션을 원하는 가정 :

using System; 
using System.Text; 
using System.Xml; 
using System.Text.RegularExpressions; 
using System.Net;    

public class SharePointList 
{ 

    public void ReadSharePointList() 
    { 
    SPList.Lists listService = new SPList.Lists(); 

      try 
      { 
       // Retreive the URL to the list web service from the application cache 
       listService.Url = "http://[server-url]/_vti_bin/Lists.asmx"; 
       // Retreive the GUID for the sharepoint list 
     // To find the GUID for your list, navigate to your SharePoint list and select Settings > List Settings. 
     // The browser url will display http://[server-url]/_layouts/listedit.aspx?List=%7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D 
     // The %7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D is your GUID that you need to transform 
     // %7B = { 
     // %2D = - 
     // %7D = } 
     // e.g. %7B7A4C9C52%2DE7E7%2D4582%2D926E%2DC70D048F9071%7D = {7A4C9C52-E7E7-4582-926E-C70D048F9071} 

       string listName = {YOUR LIST GUID HERE}; 

       // SharePoint Web Serices require authentication 
       string serviceAccountID = [USERID]; 
       string serviceAccountPW = [PASSWORD]; 
       listService.Credentials = new NetworkCredential(serviceAccountID, serviceAccountPW); 

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

       XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query",""); 
       XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields",""); 
       XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions",""); 

       ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" + 
              "<DateInUtc>TRUE</DateInUtc>"; 

       ndViewFields.InnerXml = "<FieldRef Name=\"Title\" />" + 
             "<FieldRef Name=\"Search_x0020_Value\" />"; 

       // Form a query for the list items where Start Date is null or <= today's date 
       ndQuery.InnerXml = "<Where>" + 
            "<Or>" + 
            "<IsNull><FieldRef Name=\"Start_x0020_Date\"/></IsNull>" + 
            "<Leq><FieldRef Name=\"Start_x0020_Date\"/><Value Type=\"DateTime\"><Today/></Value></Leq>" + 
            "</Or>" + 
            "</Where>" + 
            "<OrderBy><FieldRef Name=\"Sort_x0020_Order\" Ascending=\"TRUE\" /></OrderBy>"; 

       XmlNode ndListItems = listService.GetListItems(listName, null, ndQuery, ndViewFields, null, ndQueryOptions, null); 

       foreach (XmlNode node in ndListItems) 
       { 
        if (node.Name == "rs:data") 
        { 
         for (int f = 0; f < node.ChildNodes.Count; f++) 
         { 
          if (node.ChildNodes[f].Name == "z:row") 
          { 
            //DO SOMETHING WITH YOUR RESULTS 
           string test = node.ChildNodes[f].Attributes["ows_Title"].Value, node.ChildNodes[f].Attributes["ows_Search_x0020_Value"].Value; 
          } 
         } 
        } 
       } 
      } 
      catch (System.Web.Services.Protocols.SoapException ex) 
      { 
      //HANDLE ERRORS 
      } 
    } 
} 
관련 문제