Sharepoint client GetFolderByServerRelativeUrl fol

2020-07-26 11:05发布

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

         }

2条回答
贼婆χ
2楼-- · 2020-07-26 11:39

I don’t think there is any direct way to get the folder's modified data. But you can get the folder related item first, and then get the item’s modified data.

But you still cannot get the folder related item using JavaScript Object Model. You can try to get the items which content type is folder by caml query, then fetch the item whose related file's server relative url is equal to the folder's server relative url, then you can get the detailed information from the item.

var folder = rootweb.GetFolderByServerRelativeUrl("/Shared Documents/test2");

var query = new SP.CamlQuery();
query.set_folderServerRelativeUrl(“/Shared Documents”);
var items = list.getItems(query);
context.load(items, “Include(Title, FileSystemObjectType, File)”);
context.executeQueryAsync(function(){
    var itemEnum = items.getEnumerator();
    while(itemEnum.moveNext()){
       var item = itemEnum.get_current();
       if(item.get_fileSystemObjectType()==”1” && item.get_file().get_serverRelativeUrl()==”Shared Documents/test2”){
    //do something to get the modified data
}
}
}, function(){})
查看更多
Juvenile、少年°
3楼-- · 2020-07-26 11:46

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"];
    }
}
查看更多
登录 后发表回答