0

I am trying to add a new task to an existing SharePoint Tasks List using Visual Studio 2008 and SharePoint API, my code is:

using System;
using System.Collections;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

  void button1_Click(object sender, EventArgs e)
        {
            SPWeb curr = SPContext.Current.Web;
            SPListCollection lsts = curr.Lists;
            SPList myList = lsts["testfin"];
            SPListItem item = myList.Items.Add();
            item["Title"] = mytext.Text;
            item["Description"] = mytext.Text;
            item["Status"] = "Not Started";
            item.Update();
            mytext.Text = "";
        }

when I click the button, the page is refreshed with nothing happening, when I check the Tasks list, it is the same, no new task added.

can anybody help?

  • Did you tried debugging it ? I don't see anything wrong with the Code Code should Work fine. I assume that you are running this page inside the context of SharePoint, I mean the page is deployed to SharePoint ? – Kusek Nov 13 '09 at 05:11
  • Yes I'm deploying it to SharePoint, how can I debug it? do you mean putting a break-point and watch values? or something else? – Andy Harvey Nov 15 '09 at 08:35

2 Answers2

0

I assume your code in the page has a bit more to it as I don't see the button and how it's wired into that event handler, but I assume you have that all figured out.

Debugging is a good idea. Not only will it help you identify what your problem is, but it'll also help you understand the various objects in play. To debug Sharepoint, you need to attach to the w3wp.exe process, http://msdn.microsoft.com/en-us/library/dd206929.aspx

Andrew Connell wrote an article a while ago about how to setup VisStudio to attach to IIS using macros. Google that up to find out how to make your debugging life easier ... you can then make a button in VisStudio that runs the macro and attaches to the appropriate process and you're off and running.

Henry
  • 1
  • 1
0

you miss myList.Update()

  • 1
    myList.Update() is not required. I believe item.Update() is sufficient to update the list ITEM. – Sankalp May 07 '12 at 18:35