views:

247

answers:

2

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?

A: 

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
A: 

you miss myList.Update()

konradplo

related questions