我有包含列表名称和项目名称的文本文件。我需要通过它的名字获取项目guid。怎么样? (不在splist中使用foreach splistitem项导致文本文件很大并且循环将花费一定的费用)
答案 0 :(得分: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);
}
答案 1 :(得分:0)
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx或CamlQuery
SPListItemCollection items = web.Lists.GetItems(new SPQuery(){Query =“YOUR QUERY”});
答案 2 :(得分:0)
转到列表设置页面。右键单击“标题,说明和导航”并复制URL。将其粘贴到记事本中并复制字符串中“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。