Search code examples
sharepointsharepoint-2010csom

Get file size using CSOM in SharePoint 2010


I need to get the file size information from a document library in SharePoint 2010 using C# managed CSOM. Any body can give some hint or share sample code?


Solution

  • The following code gets the size of the files in document lib

    using (ClientContext oContext = new ClientContext("siteurl"))
             {
                oContext.Credentials = new NetworkCredential("LoginId", "pwd", "domain");             
                    List oList = oContext.Web.Lists.GetByTitle("DocLib");
                    CamlQuery oQuery = new CamlQuery();
                    ListItemCollection collListItem = oList.GetItems(oQuery);
                    oContext.Load(collListItem);
                    oContext.ExecuteQuery();
                    foreach (ListItem oListItem in collListItem)
                    {
    
                      oListItem["File_x0020_Size"]
    
                    }            
    
            }
    

    Let me know if it helps.