3

使用 GetFolderByServerRelativeUrl 函数时,我试图检索文件夹的“修改日期”和“创建日期”,我该怎么做?

我只能从中获取 relativeUrl 和文件夹名称。以下是我为检索文件夹所做的操作。请帮忙。

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

foreach (Folder folder in folderCollection)
         {

         }
4

2 回答 2

7

通过检索和访问您的 s 的ListItemAllFields属性Folder,您可以访问创建和修改日期,如下所示:

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"];
    }
}
于 2013-06-06T07:19:31.350 回答
0

我认为没有任何直接的方法可以获取文件夹的修改数据。但是可以先获取文件夹相关的item,然后再获取item的修改数据。

但是您仍然无法使用 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(){})
于 2013-06-06T05:20:46.000 回答