0
votes

I am dynamically adding "tasks list" item in sharepoint. my task list contains custom lookup field called "related document". so when ever i add new item in task list the same time i need to add(assign right hand side of lookupfield") "relateddocument" field. how to do this.

Simply: my value get added in RHS of the lookup column directly.

2

2 Answers

0
votes

I'm not sure I got your question right.

Do you want to add a lookupfield value to a lookup field?

EDIT:

The SPListItem ID of the related document is what you need to assign to the lookup value. Use a query or some other way of getting the SPListItem and then assign it to the lookupfield on the new task list item. Remember to allow unsafe updates on the web and to update the item.

web.AllowUnsafeUpdates=true;
taskItem["Lookup field name or ID"] = relatedDoc.ID
taskItem.Update();
0
votes
> private static void CreateDocumentItem(SPList DocumentLibrary, 
> string ItemName, string FilePath, string FileRef,string DocId,string
> ParentFolder)
>         {
>             var ParentURL = string.Empty;
>             if (!DocumentLibrary.ParentWebUrl.Equals("/"))
>             {
>                 ParentURL = DocumentLibrary.ParentWebUrl;
>             }
>             SPSecurity.RunWithElevatedPrivileges(delegate
>             {
>                 using (var site = new SPSite(DocumentLibrary.ParentWeb.Url))
>                 {
>                     using (SPWeb web = site.OpenWeb())
>                     {
>                         Hashtable propertiesHash = new Hashtable
>                                              {
>                                                  {"EYDocID",DocId}                                                 
>                                              };
>                         byte[] strm = File.ReadAllBytes(FilePath);
>                         DocumentLibrary.RootFolder.Files.Add(ParentURL + FileRef + "/" + ParentFolder + "/" + ItemName, strm, propertiesHash, false);
>                         web.AllowUnsafeUpdates = false;
>                     }
>                 }
>             });
> 
>         }`