如何從C#程序迭代SharePoint列表和子網站?是否需要爲此安裝SharePoint安裝SharePoint.dll
,或者是否存在可用於遠程訪問該數據的「Sharepoint客戶端」dll?以編程方式訪問SharePoint列表和子網站?
0
A
回答
6
使用Sharepoint Web服務;特別是Web和列表Web服務可以滿足您的要求。
對於2007年的Sharepoint: http://msdn.microsoft.com/en-us/library/bb862916(v=office.12).aspx
1
對於SharePoint 2007,您將需要訪問Web服務。在Sharepoint 2010中,有一個共享點客戶端對象模型。
http://msdn.microsoft.com/en-us/library/ee857094%28office.14%29.aspx
+1
或者如果代碼在SharePoint服務器上運行,請使用該API。 – 2010-12-13 17:13:31
0
我碰巧處理現在這事......這工作。我已經把代碼搞糊塗了,只關注機制。這是邊緣粗糙,但希望你能明白。它爲我工作。
此外,請務必使用您的Sharepoint網站的URL設置Web引用。將其用作下面的「Web參考」。
private <web reference> _Service;
private String _ListGuid, _ViewGuid;
private Initialize()
{
_Service = new <web reference>.Lists();
_Service.Credentials = System.Net.CredentialCache.DefaultCredentials;
_Service.Url = "https://sharepointsite/_vti_bin/lists.asmx";
}
private String SpFieldName(String FieldName, Boolean Prefix)
{
return String.Format("{0}{1}", Prefix ? "ows_" : null,
FieldName.Replace(" ", "_x0020_"));
}
private String GetFieldValue(XmlAttributeCollection AttributesList,
String AttributeName)
{
AttributeName = SpFieldName(AttributeName, true);
return AttributesList[AttributeName] == null ?
null : return AttributesList[AttributeName].Value;
}
public void GetList()
{
string rowLimit = "2000"; // or whatever
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement query = xmlDoc.CreateElement("Query");
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
System.Xml.XmlElement queryOptions =
xmlDoc.CreateElement("QueryOptions");
queryOptions.InnerXml = "";
System.Xml.XmlNode nodes = _Service.GetListItems(_ListGuid, _ViewGuid,
query, viewFields, rowLimit, null, null);
foreach (System.Xml.XmlNode node in nodes)
{
if (node.Name.Equals("rs:data"))
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Name.Equals("z:row"))
{
XmlAttributeCollection att =
node.ChildNodes[i].Attributes;
String title = GetFieldValue("Title");
String partNumber = GetFieldValue("Part Number");
}
}
}
}
}
}
此外,SpFieldName方法不是鐵包覆。對於列表中的大多數字段名稱,這只是一個很好的猜測。不幸的是,這是一個發現之旅。如果它們不匹配,則需要公開XML以查找實際的字段名稱。
好狩獵。
相關問題
- 1. 以編程方式刪除SharePoint 2010中的子網站
- 2. Share Sharepoint列表子網站
- 3. 如何訪問SharePoint 2010中的子網站列表
- 4. SharePoint如何獲取所有子網站,子網站列表和列表內容
- 5. 以編程方式訪問C#中的SharePoint樣式庫
- 6. 以編程方式將網站模板(.stp)添加到SharePoint
- 7. 以編程方式設置SharePoint網站的默認組
- 8. 在Sharepoint 2010中以編程方式創建我的網站
- 9. SharePoint 2007 - 如何以編程方式創建網站模板
- 10. 以編程方式在Sharepoint中創建網站集
- 11. SharePoint:以編程方式獲取網站目錄的類別
- 12. 以聲明方式或編程方式創建Sharepoint列表?
- 13. 確定指定用戶可以以編程方式訪問的SharePoint站點和站點?
- 14. SharePoint 2010:以編程方式創建的子網站的自定義主頁面
- 15. 以讀/寫模式在C#中從SharePoint網站以編程方式打開xls電子表格
- 16. 如何以編程方式從Hive訪問Sharepoint資源文件?
- 17. 以編程方式訪問SharePoint文檔庫?
- 18. 以編程方式使網站靜音
- 19. 以編程方式瀏覽網站
- 20. 以編程方式登錄網站
- 21. 以編程方式登錄網站
- 22. 以編程方式製作網站
- 23. 以編程方式將列添加到Sharepoint列表視圖
- 24. SharePoint子網站 - 遍歷列表
- 25. 以編程方式使用模擬訪問共享點列表
- 26. 以編程方式訪問CheckedTextView列表中的特定行 - Android
- 27. 以編程方式訪問實時Spark節點列表
- 28. 如何基於站點模板以編程方式創建SharePoint 2010網站
- 29. 以編程方式將SharePoint子站點遷移到其他站點集合
- 30. 編程方式創建Web應用程序和子網站
這是SharePoint 2007還是2010? – 2010-12-13 17:12:48