I need to write an application to update a list on a SharePoint 2010 site.
I found the "SPSite" which I can create with the URL, but I can't figure out how to specify with which user I want to connect.
The user isn't the current windows user, and the program isn't executed on the server.
I saw the possibility to give a "SPUserToken", but in my method I only have the user, the domain, and his password, so how can I generate this user(and I think that this user is unknown on the system executing the code, but known on the server).
Where can I specify that?
Consider using the PnP. Framework (a NuGet package), and use the AuthenticationManager object for SPO sites. This method bypasses MFA (which is mandatory in our organization, FWIW). You can find a lot more information and examples here, including steps on getting the client id and client secret for a site.
The client object model for SharePoint is a set of client-based libraries that represent the server object model. They are packaged in three different DLLs to accommodate a variety of development types. The client object model includes most of the major functions of the server API.
Use the ClientContext class to return context information about such objects as the current web application, site, site collection, or server version. The Document library templates sample app for SharePoint includes an example of how to use this object.
Since you're using the client object model, you won't be working with the SPSite class (which is part of the server object model).
Instead, you should create an instance of the ClientContext class and supply your authentication credentials through its aptly-named Credentials property. Then you can use it to fetch the List object you want to update:
using System.Net; using Microsoft.SharePoint.Client; using (ClientContext context = new ClientContext("http://yourserver/")) { context.Credentials = new NetworkCredential("user", "password", "domain"); List list = context.Web.Lists.GetByTitle("Some List"); context.ExecuteQuery(); // Now update the list. }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With