【问题标题】:how to get modifiedby property of a file for showing file details sharepoint C#如何获取文件的modifiedby属性以显示文件详细信息sharepoint C#
【发布时间】:2022-07-18 16:11:37
【问题描述】:

我想显示由用户名修改的共享点文件夹中的文件。请帮助我。还告诉我如何按日期时间排序显示此文件。

我尝试使用 docName.Add(file.ModifiedBy); 属性,但它不可用,这里是代码:

public List<string> getFiles(ClientContext CContext,string INVOICENO)
        {
            List list = CContext.Web.Lists.GetByTitle("Documents");


            CContext.Load(list);
            CContext.Load(list.RootFolder);
            CContext.Load(list.RootFolder.Folders);
            CContext.Load(list.RootFolder.Files);
            CContext.ExecuteQuery();
            FolderCollection fcol = list.RootFolder.Folders;
            List<string> docName = new List<string>();
            foreach (Folder f in fcol)
            {
                if(INVOICENO==null)
                {
                    INVOICENO = "";
                }
                string foldername = INVOICENO.ToString();
                if (f.Name == foldername)
                {
                    CContext.Load(f.Files);
                    CContext.ExecuteQuery();
                    FileCollection fileCol = f.Files;
                    foreach (File file in fileCol)
                    {
                        docName.Add(file.Name);
                        docName.Add(file.TimeLastModified.ToShortDateString());
                       

                    }
                }
            }
            return docName.ToList();

        }

【问题讨论】:

  • 您期望的输出是什么?是否要修改 docName 以获得具有以下值的字符串:John @ 10-03-2020, 23:59:59 UTC
  • 具有如下值的字符串:John @ 10-03-2020 还有 modifiedBy:username。

标签: c# sharepoint csom office-dev-pnp


【解决方案1】:

根据我的测试和研究,您可以使用CAML Query显示SharePoint文件夹中用户名修改的文件。

这个例子可以参考:(按修改时间升序排序)

    static void Main(string[] args)
    {
        var clientContext = GetonlineContext();
        Web site = clientContext.Web;

        List list = clientContext.Web.Lists.GetByTitle("Library Name");
        CamlQuery query = new CamlQuery();
        query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Editor' /><Value Type='User'>UserName</Value></Eq></Where><OrderBy><FieldRef Name='Modified' Ascending='True' /></OrderBy></Query><ViewFields /><QueryOptions /></View>";
        
        ListItemCollection collListItem = list.GetItems(query);

        clientContext.Load(collListItem);

        clientContext.ExecuteQuery();
        foreach (ListItem item in collListItem)
        {
            
            Debug.WriteLine("Name:"+item["FileLeafRef"]+"\n"+"Modified"+item["Modified"]);
        }
        clientContext.ExecuteQuery();

    }

【讨论】:

    【解决方案2】:

    在 Sharepoint 列表中,我有 3 个文件夹,例如 F1、F2 和 F3。 考虑一下,我已经修改了文件夹 F2 中的文件。

    那么如何构造 URL 以从相应文件夹中获取文件名?

    【讨论】:

      猜你喜欢
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      相关资源
      最近更新 更多