none
Files are not retrieving anymore. RRS feed

  • Question

  • Hi,

    The below code used to work, all of a sudden it doesn't retrieve files. Is something wrong with the API services at microsoft end?

    public async Task<string> GetFiles(string userID)
            {
                List<MyFiles> myFiles = new List<MyFiles>();
                string extension = "";
    
                try
                {
                    string accessToken = this.GetAccessToken();
                    
                    GraphServiceClient graphServiceClient = new GraphServiceClient((IAuthenticationProvider)new DelegateAuthenticationProvider((AuthenticateRequestAsyncDelegate)(requestMessage =>
                    {
                        requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
                        return (Task)Task.FromResult<int>(0);
                    })), (IHttpProvider)null);
    
                    foreach (DriveItem driveItem in (IEnumerable<DriveItem>)await graphServiceClient.Users[userID].Drive.Root.Children.Request().GetAsync())
                    {
                        if (driveItem.Name.EndsWith(".docx") || driveItem.Name.EndsWith(".doc"))
                            extension = "doc";
                        else if (driveItem.Name.EndsWith(".xlsx") || driveItem.Name.EndsWith(".xls"))
                            extension = "xls";
                        else if (driveItem.Name.EndsWith(".pptx") || driveItem.Name.EndsWith(".ppt"))
                            extension = "ppt";
                        myFiles.Add(new MyFiles()
                        {
                            Name = driveItem.Name,
                            WebURI = driveItem.WebUrl + "?web=1",
                            ID = driveItem.WebUrl + "?web=1",
                            Extension = extension,
                            CreatedDate = driveItem.CreatedDateTime.Value.ToString("dd-MMM-yyyy")
                        });
                    }
                }
                catch (Exception ex)
                {
    
                }
                extension = (string)null;
                return JsonConvert.SerializeObject((object)myFiles);
            }

    Nashaq.
    • Edited by Nashaq Thursday, February 14, 2019 7:47 AM
    Thursday, February 14, 2019 7:34 AM

Answers

  • Hi

    If it works again, there may be something wrong at Microsoft server end.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    • Marked as answer by Nashaq Friday, February 15, 2019 3:54 AM
    Friday, February 15, 2019 2:46 AM

All replies

  • Hi

    Is there any permission related factors?


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    Thursday, February 14, 2019 9:23 AM
  • Hi Justin,

    It started working again, following are the permission given,

    Microsoft Graph - > Application Permission

    1. Read directory data

    2. Read and write directory data

    3. Read and write files in all site collections

    4. Read files in all site collections

    Delegated Permissions

    None given

    Windows Azure Active Directory - > Application Permission 

    None given

    Delegated Permissions

    1. Sign in and read user profile

    Is there any permissions have missed?

    Basically what I want to do is,

    1. Create an office 365 account using the api

    2. Retrieve all the files for an user

    Nashaq.



    • Edited by Nashaq Thursday, February 14, 2019 10:39 AM
    Thursday, February 14, 2019 10:37 AM
  • Hi

    If it works again, there may be something wrong at Microsoft server end.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    • Marked as answer by Nashaq Friday, February 15, 2019 3:54 AM
    Friday, February 15, 2019 2:46 AM