2010-11-19 48 views
1

我有列表名稱和項目名稱的文本文件。我需要通過它的名字獲得物品指導。怎麼樣? (不使用splist列表中的foreach splistitem項導致文本文件很大,並且循環將會花費)得到一個listitem的指導

+0

如果你想查找每個項目,你將不得不使用某種循環......你能包含更多關於「項目名稱」的信息嗎?這些文件是?列出項目? 「項目名稱」在SharePoint中映射到哪個列? – 2010-11-19 14:59:48

回答

0

您可能有足夠的信息使用SPWeb功能GetListItem,否則您將需要嘗試SPWeb.SearchListItems。這兩者都不會一帆風順。

的Web服務有一個,我已經使用了一個體面的搜索功能,例如:

public static string GetPageId(string listName, string webPath, string pageTitle) 
     { 
      string pageId = ""; 
      IntranetLists.Lists lists = new IntranetLists.Lists(); 
      lists.UseDefaultCredentials = true; 
      lists.Url = webPath + "/_vti_bin/lists.asmx"; 
      XmlDocument doc = new XmlDocument(); 
      doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + pageTitle + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>"); 
      XmlNode listQuery = doc.SelectSingleNode("//Query"); 
      XmlNode listViewFields = doc.SelectSingleNode("//ViewFields"); 
      XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions"); 

      Guid g = GetWebID(webPath); 

      XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString()); 
      foreach (XmlNode listItem in SPCollection.XpathQuery(items, "//sp:listitems/rs:data/z:row")) 
      { 
       XmlAttribute id = listItem.Attributes["ows_Id"]; 
       if (id != null) 
       { 
        pageId = id.Value;      
       } 

      } 
      return pageId;    
     } 

public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery) 
    { 
     XmlDocument doc = new XmlDocument(); 
     doc.LoadXml(xmlToQuery.OuterXml); 
     XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable); 
     mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/"); 
     mg.AddNamespace("z", "#RowsetSchema");         
     mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset"); 
     mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois"); 
     mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2"); 
     mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory"); 
     return doc.SelectNodes(xPathQuery, mg); 
    } 
0

轉到列表設置頁面。右鍵點擊「標題,說明和導航」並複製網址。將其粘貼到記事本中,並在字符串中的「List =」後複製所有內容。這是您的列表的URL編碼GUID。所有你需要做的就是在這裏進行解碼http://www.albionresearch.com/misc/urlencode.php

來源:http://weblogs.asp.net/jimjackson/archive/2008/02/11/get-a-sharepoint-list-guid-from-the-browser.aspx

這是手動獲得一定的列表中的每個GUID。

相關問題