Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
share|improve this question
add comment

1 Answer

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:

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

Hope it helps :)

share|improve this answer
    
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 Sharepoint Dec 6 '12 at 10:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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