0
我正在调用Sharepoint web服务methond GetListItems,并且没有看到任何有关正在返回的文件/文件夹大小。我错过了什么,或者有另一种方法来获取文件/文件夹的大小。提前谢谢了。使用GetListItems从Sharepoint获取文件/文件夹大小
我正在调用Sharepoint web服务methond GetListItems,并且没有看到任何有关正在返回的文件/文件夹大小。我错过了什么,或者有另一种方法来获取文件/文件夹的大小。提前谢谢了。使用GetListItems从Sharepoint获取文件/文件夹大小
你需要的字段叫做ows_FileSizeDisplay,这将返回一个int字节数。
这里是一些代码,把你的分辩轨道
List<File> files = new List<File>(1);
File tempFile;
#region Get SharePointItems
SharePointListService.Lists svc = new SharePointListService.Lists();
XmlNode spItemsNode;
try
{
svc.Credentials = System.Net.CredentialCache.DefaultCredentials;
svc.Url = baseSharePointPath+"/_vti_bin/Lists.asmx";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode queryOptions =
xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
queryOptions.InnerXml = "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><DateInUtc>TRUE</DateInUtc><Folder>" +
baseSharePointPath + "/"+ listName + "/"+ folderName + "</Folder></QueryOptions>";
XmlNode query =
xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
query.InnerXml = "<Where><Eq><FieldRef Name='Usage'/><Value Type='Text'>%%usage%%</Value></Eq></Where>";
query.InnerXml = query.InnerXml.Replace("%%usage%%", ConvertFileUsageToString(usage));
spItemsNode = svc.GetListItems(listName,
null, query, null, null, queryOptions, null);
}
finally
{
svc.Dispose();
}
// load the response into an xml document
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(spItemsNode.OuterXml);
// create a namespace manager
XmlNamespaceManager ns = new XmlNamespaceManager(xDoc.NameTable);
// add all the special SharePoint Namespaces in
ns.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
ns.AddNamespace("z", "#RowsetSchema");
ns.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
ns.AddNamespace("s", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882");
ns.AddNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882");
XmlNodeList Items = xDoc.SelectNodes(@"/sp:listitems/rs:data/z:row", ns);
#endregion
foreach (XmlNode currentFile in Items)
{
tempFile = new File();
tempFile.Name = currentFile.Attributes["ows_NameOrTitle"].Value;
tempFile.Type = currentFile.Attributes["ows_DocIcon"].Value;
tempFile.Usage = ConvertToFileUsage(currentFile.Attributes["ows_Usage"].Value);
tempFile.Data = getFileBytes(currentFile.Attributes["ows_RequiredField"].Value, baseSharePointPath);
files
这里上是一个不错的代码片段,如果您有任何疑问
Folder folder = getFolder(serverRelitiveURL);
FileCollection files = folder.Files;
folder.Context.Load(files);
folder.Context.ExecuteQuery();
int folderSize;
foreach(file in files)
{
ListItem li = file.ListItemAllFields;
Console.writeline(li["File_x0020_Size"]);
folderSize = li["File_x0020_Size"]+folderSize;
}
Console.writeline(folderSize);
我没有得到,这将做的工作呼喊财产从这个方法回报。我也尝试添加查询选项,但没有在任何地方看到ows_FileSizeDisplay。 – user420
它应该在currentFile.Attributes [“ows_FileSizeDisplay”]中。值您使用的是哪个版本的SharePoint,以及您查询的是哪种类型的列表? – Stuart
非常感谢,斯图尔特。我通过传递query和queryOption来调用方法来解决这个问题,就像你已经显示的那样,但是对于innerXml使用“”。它工作并获得了ows_FieldSizeDisplay列。我会把我后来做的事情的细节。再次感谢您的帮助。 – user420