我正在尝试使用GetFolderByServerRelativeUrl函数检索文件夹的“修改日期”和“创建日期”,我该怎么办?
我只能从中获取relativeUrl和文件夹名称。下面是我检索文件夹的方法。请帮忙。
FolderCollection folderCollection = rootweb.GetFolderByServerRelativeUrl("/Shared Documents/test2").Folders;
spClientContext.Load(folderCollection);
foreach (Folder folder in folderCollection)
{
}
答案 0 :(得分:6)
通过检索和访问Folder
的{{3}}属性,您可以按如下方式访问创建和修改的日期:
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"];
}
}
答案 1 :(得分:0)
我认为没有任何直接的方法来获取文件夹的修改数据。但您可以先获取文件夹相关项,然后获取项目的修改数据。
但您仍然无法使用JavaScript对象模型获取与文件夹相关的项目。您可以尝试通过caml查询获取内容类型为文件夹的项目,然后获取其相关文件的服务器相对URL等于文件夹的服务器相对URL的项目,然后您可以从该项目中获取详细信息。
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(){})