2010-09-16 30 views
0

我成功地使用sharepoint對象Model來更新其中一個字段(布爾類型爲infopath),就像它是一個列表項一樣。如何以編程方式更新infopath表單庫項目字段?

但是對於文本類型的另一個字段,只需執行相同的代碼,但不會更改字段值!

我正在使用下面的代碼,它適用於該布爾字段,但對於字符串類型的另一個字段,不知道爲什麼它不工作。任何想法 ?

SPSecurity.RunWithElevatedPrivileges(delegate() 

{ 
SPWeb web; 

SPSite site = new SPSite("http://sharepointsite"); 
web = site.OpenWeb(); 

SPList formLibList = web.Lists["FormLibraryName"]; 

SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + titleName + "</Value></Eq></Where>"; 
web.Site.WebApplication.FormDigestSettings.Enabled = false; 

web.AllowUnsafeUpdates = true; 
SPListItemCollection col = formLibList.GetItems(query); 

if (col.Count > 0) 
{ 

col[0]["CustomerName"] = "test customer name"; 
col[0].Update(); 

} 

web.Site.WebApplication.FormDigestSettings.Enabled = true; web.AllowUnsafeUpdates = false; 
}); 

感謝,

尼基爾

+0

明白了,我不得不聲明SPListItem並設置它而不是直接修改列表項集合。 – 2010-09-16 07:01:38

回答

0

我不得不宣佈SPListItem並設置它,而不是直接修改列表項集合。

0

這不是您的問題的答案(您自己已經找到了解決方案),但是您可能希望將SPSite和SPWeb對象放入使用塊中。在你的示例代碼中,你不會處理它們,這會導致內存泄漏。正確的方法是這樣的:

SPSecurity.RunWithElevatedPrivileges(delegate() 
{ 
    using (SPSite site = new SPSite("http://sharepointsite")) 
    { 
     using (SPWeb web = site.OpenWeb()) 
     { 
      // the rest of your code 
     } 
    } 
}); 
+0

是的,謝謝你指出。 – 2010-09-20 03:54:25

相關問題