Get file/folder size from sharepoint using GetListItems

sharepoint

I am calling Sharepoint web service methond GetListItems, and don't see anything about file/folder size being returned. Am I missing something, or is there another way to get the size of the file/folder. Many thanks in advance.

Best Answer

the field you need is called ows_FileSizeDisplay, this returns an int for the number of bytes.

here is some code to put you on the rigth track

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
Related Topic