C# Sharepoint 客户端 GetFolderByServerRelativeUrl 文件夹修改日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16931355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:09:38  来源:igfitidea点击:

Sharepoint client GetFolderByServerRelativeUrl folder modified date

c#sharepointclient-side

提问by tang fire

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

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

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

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

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

foreach (Folder folder in folderCollection)
         {

         }

回答by Douglas

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.

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

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.

但是您仍然无法使用 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(){})

回答by Rawling

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

通过检索和访问ListItemAllFields您的Folders的属性,您可以按如下方式访问创建和修改日期:

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"];
    }
}