プログラムでリストに項目を追加しながら、更新しようとしているフィールドは読み取り専用エラーです。
-
10-12-2019 - |
質問
Webパーツページからリダイレクトされているアプリケーションページからリスト項目を追加しています。
マイコードは次のとおりです。
protected void Page_Load(object sender, EventArgs e)
{
SPSite site = new SPSite("http://bipc11:1234/sites/webparts");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPUser currentUser = web.CurrentUser;
SPList list = web.Lists["Cart"];
SPListItem item = list.AddItem();
item["Picture"] = Request.QueryString["title"];
Response.Write("<script> alert('Pictrue Updated')</script>");
item["User"] = currentUser;
Response.Write("<script> alert('User Updated')</script>");
item.Update();
Response.Write("<script> alert('Item Updated')</script>");
web.Update();
web.AllowUnsafeUpdates = false;
Response.Write("<script> alert('Value Added To Cart Successfully')</script>");
Response.Redirect(Microsoft.SharePoint.Utilities.SPUrlUtility.CombineUrl(web.Url, "/SiteAssets/WebPartPage.aspx"));
}
.
ここにPicture
は、Cart
リストでルックアップ型です。User
は、人またはグループの種類です。アプリケーションページにリダイレクトするためのJavaスクリプトは次のとおりです。
function myfunction(title)
{
window.location.assign("http://bipc11:1234/sites/webparts/_layouts/AddValueToCartList/AddValueToCartList.aspx?title="+title);
}
.
ページがアプリケーションページにリダイレクトされているとき、私は上記のエラーが発生しています。
私は何を見逃していますか?助けてください。
解決
I am unable to find the exact reason for the error: However pls go through the following points:
1) How to update a Readonly field.
First set Readonly to false and update the field and then revert it back as:
Field.ReadOnlyField = false;
Field.Update();
2) Updating the Lookupfield:
new SPFieldLookupValue(1, "ASP.Net");
所属していません sharepoint.stackexchange