使用GetListItems从sharepoint获取文件/文件夹大小

时间:2011-10-13 14:27:42

标签: sharepoint

我正在调用Sharepoint Web服务methond GetListItems,并且看不到有关返回文件/文件夹大小的任何信息。我错过了什么,或者是否有其他方法来获取文件/文件夹的大小。非常感谢提前。

2 个答案:

答案 0 :(得分:3)

您需要的字段称为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

答案 1 :(得分:0)

如果您有任何问题,这是一个很好的代码片段,可以帮助您解决问题

        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);