Sharepoint客户端GetFolderByServerRelativeUrl文件夹修改日期
本文关键字:修改 日期 文件夹 GetFolderByServerRelativeUrl 客户端 Sharepoint | 更新日期: 2023-09-27 18:17:01
我试图检索"修改日期"answers"创建日期"文件夹时使用GetFolderByServerRelativeUrl函数,我怎么能做到这一点?
我只能得到relativeUrl和文件夹名称。下面是我检索文件夹所做的。请帮助。
FolderCollection folderCollection = rootweb.GetFolderByServerRelativeUrl("/Shared Documents/test2").Folders;
spClientContext.Load(folderCollection);
foreach (Folder folder in folderCollection)
{
}
通过检索和访问Folder
s的ListItemAllFields
属性,您可以访问创建和修改的日期,如下所示:
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"];
}
}
我不认为有任何直接的方法来获得文件夹的修改数据。但是您可以先获取与文件夹相关的项,然后再获取该项的修改数据。
但是您仍然无法使用JavaScript对象模型获得文件夹相关项。您可以尝试通过caml查询获取内容类型为folder的条目,然后获取相关文件的服务器相对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(){})