Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint client GetFolderByServerRelativeUrl folder modified date

I am trying to retrieve "Modified Date" and "Created Date" for folders when using GetFolderByServerRelativeUrl function, how can i do it?

I only able to get relativeUrl and folder Name out of it. below is what i did to retrieve the folder. Please help.

FolderCollection folderCollection = rootweb.GetFolderByServerRelativeUrl("/Shared Documents/test2").Folders;
spClientContext.Load(folderCollection);

foreach (Folder folder in folderCollection)
         {

         }
like image 551
tang fire Avatar asked Oct 25 '25 09:10

tang fire


1 Answers

By retrieving and accessing the ListItemAllFields property of your Folders, you can access the created and modified dates as follows:

using (ClientContext spClientContext = new ClientContext("http://whatever"))
{
    var rootweb = spClientContext.Web;

    FolderCollection folderCollection =
        rootweb.GetFolderByServerRelativeUrl("/Shared Documents/test2").Folders;

    // Don't just load the folder collection, but the property on each folder too
    spClientContext.Load(folderCollection, fs => fs.Include(f => f.ListItemAllFields));

    // Actually fetch the data
    spClientContext.ExecuteQuery();

    foreach (Folder folder in folderCollection)
    {
        // This property is now populated
        var item = folder.ListItemAllFields;

        // This is where the dates you want are stored
        var created = (DateTime)item["Created"];
        var modified = (DateTime)item["Modified"];
    }
}
like image 184
Rawling Avatar answered Oct 26 '25 23:10

Rawling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!