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)
{
}
By retrieving and accessing the ListItemAllFields
property of your Folder
s, 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"];
}
}
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(){})