1

I have a custom web part which have lot of fields that will be filed out by user and on submit is there a way that i can populate these values into a SharePoint list .I don't want to use info path as the web part also has lot of C# code in the background

 SPWeb app = SPContext.Current.Web;
            SPList ListName = app.Lists["Communities Directory"];
            SPListItem ListItem = ListName.Items.Add();
            string[] UsersSeperated = pickAdministrators.CommaSeparatedAccounts.Split(',');
            SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
            foreach (string UserSeperated in UsersSeperated)
            {

                app.EnsureUser(UserSeperated);
                SPUser User = app.SiteUsers[UserSeperated];
                SPFieldUserValue UserName = new SPFieldUserValue(app, User.ID, User.LoginName);
                UserCollection.Add(UserName);
            }
            ListItem["Contact Person"] = UserCollection;
3

you can and would need to use the following:

Lists Web Sevice

Lists.UpdateListItems Method (Lists)

more can be found at:

http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems(v=office.12).aspx

or

In the codebehind for the webpart you could do:

SPWeb app = SPContext.Current.Web; 
SPList ListName = app.Lists["YourListName"]; 
SPListItem ListItem = ListName.Items.Add(); 
ListItem["field1Name"] = value; 
ListItem["field2Name"] = value; 
ListItem.Update(); 

taken from here:

https://stackoverflow.com/questions/6569481/add-items-to-existing-sharepoint-lists-by-coding

Hope it helps :)

  • Hi I am trying to update the share point list item with people picker field and i am using the following code but its always giving me specified user not found error .I pasted my code in the question .CAn you please help me with that – Anil Oct 25 '12 at 22:54
  • hi sorry for the late reply been bussy! have you managed to solve the issue? have you debugged the code to see where exactly its breaking on? – Ali Jafer Dec 6 '12 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.