Adding Items to List in By using Admin account or Any other domain account
Dear All,
Some time you want to add the item in the list which user doesn't have a permission, the below code will impersonate the user in sharepoint to add the code in the list by using domain account
using System.Collections.Generic;
using System.Linq;
using System.Text;
//SharePoint namespace
using Microsoft.SharePoint.Client;
namespace AddItemsToList
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "http://sharepointserver.com";
ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = newSystem.Net.NetworkCredential(@"domain/userName", "password","domain.com");
Web site = clientContext.Web;
//Getting List
List list = site.Lists.GetByTitle("Students");
//Adding Items to List
ListItemCreationInformation listItemCreationInformation = newListItemCreationInformation();
ListItem listItem = list.AddItem(listItemCreationInformation);
listItem["Title"] = "1";
listItem["First Name"] = "John";
listItem["Last Name"] = "Abraham";
listItem["Age"] = 35;
listItem.Update();
listItem = list.AddItem(listItemCreationInformation);
listItem["Title"] = "2";
listItem["First Name"] = "Sharukh";
listItem["Last Name"] = "Khan";
listItem["Age"] = 40;
listItem.Update();
clientContext.ExecuteQuery();
Console.WriteLine("Items Added Successfully To List");
Console.ReadLine();
}
}
}
Regards
3art Technology Experts
http://www.3art.tech
Comments
Post a Comment