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

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,807 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    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