Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

.net form writing to SP list crashes app pool

$
0
0

Okay weird thing going on here. I built a form running in the layouts folder that writes to a custom list. Everything appeared to be working as planned. However, after a few submissions I stumbled up errors when trying to go into list settings, create a view, etc.. of the custom list. If I recyle the app pool I can access all those pages again.

Code:

public partial class IdeaInventory : System.Web.UI.Page 
{
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        base.MasterPageFile = SPContext.Current.Web.MasterUrl;
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        btnSubmit.Click += new EventHandler(btnSubmit_Click);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.CheckCustomRights();
            PopulateCheckBoxes();
        }
    }
    private void PopulateCheckBoxes()
    {
        //populate check box lists
        SPSite mySite = new SPSite(SPContext.Current.Site.ID);
        SPWeb myWeb = mySite.OpenWeb("/members/leadership/ts/");
        SPList ideaInventory = myWeb.Lists["Idea Inventory"];
        //strategic fit column
        SPField sf = ideaInventory.Fields["Strategic Fit"];
        SPFieldMultiChoice strategicFit = (SPFieldMultiChoice)sf;
        for (int item = 0; item < strategicFit.Choices.Count; item++)
        {
            cblFit.Items.Add(new ListItem(strategicFit.Choices[item], strategicFit.Choices[item]));
        }
        //project type column
        SPField pt = ideaInventory.Fields["Project Type"];
        SPFieldMultiChoice projectType = (SPFieldMultiChoice)pt;
        for (int item = 0; item < projectType.Choices.Count; item++)
        {
            cblType.Items.Add(new ListItem(projectType.Choices[item], projectType.Choices[item]));
        }
        mySite.Close();
        myWeb.Close();
        mySite.Dispose();
        myWeb.Dispose();
    }
    private void CheckCustomRights()
    {
        bool userCheckedForCustomLogic = false;
        //write here a custom logic to check if user has enough rights to access application page
        //if yes, set userCheckedForCustomLogic to true;
        SPGroup spgOwners = SPContext.Current.Web.Groups["Net Owners"];
        SPGroup spgMembers = SPContext.Current.Web.Groups["Net Members"];
        if (spgOwners.ContainsCurrentUser || spgMembers.ContainsCurrentUser)
            userCheckedForCustomLogic = true;
        if (!userCheckedForCustomLogic)
        {
            Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
       // SPWeb mySite = SPContext.Current.Web;
      // SPListItemCollection listItems = mySite.Lists["Idea Inventory"].Items;
      // Response.Write(mySite);
        SPSite mySite = new SPSite(SPContext.Current.Site.ID);
        SPWeb myWeb = mySite.OpenWeb("/members/leadership/ts/");
       // Response.Write(refWeb);
        SPListItemCollection listItems = myWeb.Lists["Idea Inventory"].Items;
        myWeb.AllowUnsafeUpdates = true;
        SPListItem item = listItems.Add();
        SPFieldMultiChoiceValue sfvalue = new SPFieldMultiChoiceValue();
        foreach (ListItem relevance in cblFit.Items)
        {
            if (relevance.Selected)
                sfvalue.Add(relevance.Text);
        }
        item["Strategic Fit"] = sfvalue;
        SPFieldMultiChoiceValue ptvalue = new SPFieldMultiChoiceValue();
        foreach (ListItem type in cblType.Items)
        {
            if (type.Selected)
                ptvalue.Add(type.Text);
                
        }
            item["Project Type"] = ptvalue;
           
       
        item["Product Idea"] = txtIdea.Text;
        item["Title"] = txtIdea.Text;
        item["Full Name"] = txtName.Text;
        item["Date Created"] = DateTime.Today;
        //item["Project Type"] = cblType.SelectedItem;
        item["Short Description"] = txtDescription.Text;
        item["Idea Sponsors"] = txtSponsors.Text;
        //item["Strategic Fit"] = cblFit.Text;
        item["Success Factors"] = txtFactors.Text;
        item["Product Markets"] = txtMarket.Text;
        item["Other Considerations"] = txtConsiderations.Text;
        item.Update();
        mySite.Close();
        myWeb.Close();
        mySite.Dispose();
        myWeb.Dispose();
        Panel1.Visible = false;
        ltlResult.Text = "Thank you for your idea!";
        
    }
}


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>