开发者

Does anyone see why this SharePoint code returns Null?

I keep getting a "Value cannot be null." Ive tried changing several things but just cant figure it out any help.

    List<int> selecteditems = new List<int>();
    int itemnum = 0;

    double totalsiteitems1 = (Double)ViewState["NoFiles"];
    for (int i = 1; i <= totalsiteitems1; i++)
    {
        itemnum = Int32.Parse(Request.Form["option" + i]);
        selecteditems.Add(itemnum);
    }
    foreach (int pubitem in selecteditems)
    {
        SPSite oSite = new SPSite(site);
        SPWeb oWeb = oSite.OpenWeb();
        SPList oList = oWe开发者_JS百科b.Lists[list];
        SPListItem oListItem = oList.Items.GetItemById(pubitem);
        oListItem["_ModerationStatus"] = 0;
        oListItem.Update(); 
    }


  1. Be sure that Request.Form["option" + i] returns something and that it can be parsed to integer.
  2. Also be sure that ViewState["NoFiles"] returns something.


I would suggest using TryParse

http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx

  if(Int32.TryParse(Request.Form["option" + i], out itemnum)) {
      selecteditems.Add(itemnum);
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜