1

I want to display files from a sharepoint folder that were modified by username. please help me for this. Also tell me how to show this file with sorting order by datetime.

I tried using docName.Add(file.ModifiedBy); property but its not available, here is the code:

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();

        }
Hugo
  • 2,077
  • 2
  • 28
  • 34
  • What is the output you're expecting? Do you want to modify `docName` to have strings with values like: `John @ 10-03-2020, 23:59:59 UTC`? – CthenB Mar 17 '22 at 16:24
  • have strings with values like: John @ 10-03-2020 also modifiedBy:username. – Salman Patel Mar 19 '22 at 04:51

1 Answers1

1

According to my testing and research, you can use CAML Query to display the files modified by the username from the SharePoint folder.

Here is an example you can refer to:(sorted by modification time in ascending order)

    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();

    }

enter image description here

Zella_msft
  • 372
  • 2
  • 4