Upload a file on one drive using microsoft graph api in c# asp.net

Alisha Mulla 0 Reputation points


I have one question,I want to upload a file on one drive and it is worked properly in console application but not  in web application. Please help me

here below is my sample console application code.


 var clientID = "
            var clientSec = "****";
            var tenant = "****";
            var userID = "***";

            var filePath = @"C:\onedrivedoc\LRN DRAFT retail (1).docx";
            var fileName = "LRN DRAFT retail (1).docx";

            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder

            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
            var graphClient = new GraphServiceClient(authProvider);

            StreamReader reader = System.IO.File.OpenText(filePath);

            var uploadedFile = graphClient.Users[userID].Drive.Root.ItemWithPath(fileName).Content.Request().PutAsync
A set of technologies in the .NET Framework for building web applications and XML web services.
3,185 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,216 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Carlos Solís Salazar 15,921 Reputation points

    To grant Permission for your App registration, you require to follow the next steps:

    1. In the navigation pane, click API permissions.
    2. Click Add a permission. The Request API permissions pane appears.
    3. Click Microsoft Graph tile.
    4. Click Application permissions.
    5. Select the following permissions:
      • Directory: Directory.Read.All
      • Files: Files.ReadWrite.All
      • User: User.Read.All
      • Notes: Notes.ReadWrite.All
      • Application: Application.ReadWrite.All
    6. Click Add permissions.
    7. Click Add a permission. The Request API permissions pane appears.
    8. Click Grant admin consent for tenant_name.
    9. Click Yes.

    Hope this helps!

    Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.

    NOTE: To answer you as quickly as possible, please mention me in your reply.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more