SharePoint : how to authenticate from c#
sharepoint
Solution
Make the user you want to run the code under known in SharePoint, then, using
`SPSite.RootWeb.EnsureUser("username").UserToken` you can get that user's SPUserToken use that to open the SPSite, like so
var token = SPSite.RootWeb.EnsureUser("usernameToImpersonate").UserToken;
using (SPSite site = new SPSite(token, this.ListAddress))
{
using (SPWeb web = site.OpenWeb())
{
// code here will be executed as selected user
}
}
Problem
I have the following code snippet: ``` using (SPSite site = new SPSite(this.ListAddress)) { using (SPWeb web = site.OpenWeb()) { } } ``` How can I authenticate so that I can set a domain username + password in a configuration file.