Esempio n. 1
0
        private long GetWebSize(Web currentWeb)
        {
            long tmpSize = 0;

            ClientRuntimeContext clientContext = currentWeb.Context;

            clientContext.Load(currentWeb);
            clientContext.ExecuteQuery();

            //ListCollection lists = currentWeb.Lists;
            //clientContext.Load(lists);
            //clientContext.ExecuteQuery();

            var Libraries = clientContext.LoadQuery(currentWeb.Lists.Where(l => l.BaseTemplate == 101));

            clientContext.ExecuteQuery();

            foreach (List tmpList in Libraries)
            {
                clientContext.Load(tmpList);
                clientContext.ExecuteQuery();

                string Query = String.Concat(
                    "<View>",
                    "<ViewFields>",
                    "<FieldRef Name='Title'/>",
                    "<FieldRef Name='ID'/>",
                    "<FieldRef Name='File_x0020_Size'/>",
                    "</ViewFields>",
                    "</View>");

                CamlQuery          oQuery        = new CamlQuery();
                ListItemCollection collListItems = tmpList.GetItems(oQuery);
                clientContext.Load(collListItems);

                //FileCollection listFiles = tmpList.RootFolder.Files;
                //clientContext.Load(listFiles,
                //	files => files.Include(file => file.ETag),
                //	files => files.Include(file => file.ListItemAllFields["File_x0020_Size"]));

                clientContext.ExecuteQuery();

                foreach (ListItem oListItem in collListItems)
                {
                    clientContext.Load(oListItem);
                    clientContext.ExecuteQuery();

                    var fileSize = (string)oListItem["File_x0020_Size"];

                    int itemFileSize = String.IsNullOrEmpty(fileSize) ? 0 : int.Parse(fileSize);

                    tmpSize += itemFileSize;
                }
            }

            return(tmpSize);
        }