How to read data from excel file from sharepoint in C# .net framework using webaddress of the file in Excel.Path

Mohsin Raza 21 Reputation points
2022-11-30T12:38:52.64+00:00

hello:

Can i get some help to find the answer ,how to read data from excel file in company sharepoint in C# .net framework using webaddress of the file ?

Regards

Microsoft 365 and Office | SharePoint | Development
Developer technologies | C#
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-12-01T08:49:19.987+00:00

    Hi @Mohsin Raza
    Per my test, you can use the following code to get excel file in sharepoint

    using (ClientContext ctx = new ClientContext("https://xxx.sharepoint.com/sites/aaa"))  
    {  
      
        ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);  
      
        Web web = ctx.Web;  
      
        ctx.Load(web, a => a.ServerRelativeUrl);  
      
        ctx.ExecuteQuery();  
      
        FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, "/sites/aaa/Coding/1/sssss.xlsx");  
        ctx.ExecuteQuery();  
      
        var filePath = @"c:\abc\Test\sssss.xlsx";  
        using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))  
        {  
            fileInfo.Stream.CopyTo(fileStream);  
        }  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.