2011-10-13 118 views

回答

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 
+0

我沒有得到,這將做的工作呼喊財產從這個方法回報。我也嘗試添加查詢選項,但沒有在任何地方看到ows_FileSizeDisplay。 – user420

+0

它應該在currentFile.Attributes [「ows_FileSizeDisplay」]中。值您使用的是哪個版本的SharePoint,以及您查詢的是哪種類型的列表? – Stuart

+0

非常感謝,斯圖爾特。我通過傳遞query和queryOption來調用方法來解決這個問題,就像你已經顯示的那樣,但是對於innerXml使用「」。它工作並獲得了ows_FieldSizeDisplay列。我會把我後來做的事情的細節。再次感謝您的幫助。 – user420

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