0

I already searched in Stackoverflow and found few samples using Interop.Excel.

I am using Office 2016 and Interop.Excel is targeted at 2013. I want to read an excel file located in a Sharepoint path from my C# application. User will change a cell value from the application and it should get updated in the Sharepoint file.

I checked few samples of ClosedXML but these are accessing local file and not Sharepoint.

RKh
  • 13,818
  • 46
  • 152
  • 265

1 Answers1

1
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.

ClientContext context = new ClientContext("https://{site_url}");

GroupCollection siteGroups = context.Web.SiteGroups;

// Assume that there is a "Members" group, and the ID=5.
Group membersGroup = siteGroups.GetById(5);

// Let's set up the new user info.
UserCreationInformation userCreationInfo = new UserCreationInformation();
userCreationInfo.Email = "user@domain.com";
userCreationInfo.LoginName = "domain\\user";
userCreationInfo.Title = "Mr User";

// Let's add the user to the group.
User newUser = membersGroup.Users.Add(userCreationInfo);

context.ExecuteQuery();

I hope a sample code helps.

Alpovo
  • 1
  • 3
  • I guess my URL is not working. How the sharepoint URL should look like ? I copied the URL from Sharepoint folder where my file is located but it is throwing error: "Count 0. Sitegroups" – RKh Jul 28 '21 at 12:06
  • https://stackoverflow.com/questions/19505513/open-an-excel-file-from-sharepoint-site could you take a look? Can you translate it written in a different language (VS Vbasic to c#)? did it help? – Alpovo Jul 28 '21 at 14:12
  • Can someone provide the code working for .net(c#) – Shirsh Mar 03 '22 at 15:58