2011-10-31 32 views
0

我在sharepoint中動態添加「任務列表」項。我的任務列表包含稱爲「相關文檔」的自定義查找字段。所以當我在任務列表中添加新項目的同時,我需要添加(指派lookupfield的右側「)」related document「字段,如何執行此操作。 。查找列直接如何在sharepoint查詢列中添加(分配)項目?

回答

0

我不知道我把你的問題的權利

你想一個lookupfield值添加到查找字段

編輯:?

的SPListItem的ID相關文件是你需要分配給的查找值。使用查詢或其他方式獲取SPListItem,然後將其分配給新任務列表項上的查找字段。請記住允許網上不安全的更新並更新該項目。

web.AllowUnsafeUpdates=true; 
taskItem["Lookup field name or ID"] = relatedDoc.ID 
taskItem.Update(); 
+0

是啊,我能夠增加對任務列表。對於文檔庫我無法添加它。我試圖更新查閱字段,並試圖傳遞查找值作爲散列表參數,但沒有運氣... – TinTin

0
> 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; 
>      } 
>     } 
>    }); 
> 
>   }` 
相關問題