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.