Saturday, August 30, 2008

Event handler is not trigged from console app.

A few days ago when try to test an event handler, I've build a simple console app. and add from code an item to a list. Surprise ! ItemAdded() was not called. So I'd write an email to some sharepoint gurus.
Here is the content of the email send by me to Robert L. Bogue :

Hello Robert,

Thanx for great posts about sharepoint. I do have a simple problem. I build a simple console app:

        static void Main(string[] args)
{
using (SPSite site = new SPSite("http://ovidiubeches/"))
{
using (SPWeb web = site.OpenWeb("dt"))
{
web.AllowUnsafeUpdates = true;

SPList list = web.Lists["Tasks"];
SPListItem item = list.Items.Add();
item["Title"] = "new item " + DateTime.Now.ToString();
item.Update();

web.AllowUnsafeUpdates = false;
}
}
}

THE PROBLEM is that when item is added from console app the ItemAdded() event hanlder is not called, but when item is added from browser everything works perfect. What is the explanation ? Any solution to that except using web services from console app ?
I usual need console app to add / edit items for testing. Sometime I do have fields that are hiddend or too complex to populate them by hand. So any sugestion to this will be great !

Many thanx,

Ovidiu B E C H E S - P U I A
Software Developer


After 2 days I've got the reply from him:

I wish I could tell you what's going on -- but I don't know. I'd post something in the forums. More people are looking at that stuff -- including some MS folks paid to respond.

Rob

-------------------
Robert L. Bogue, MS MVP: Microsoft Office SharePoint Server, MCSE, MCSA:Security, etc.
Blog: http://www.thorprojects.com/blog
Have you heard about The SharePoint Shepherd's Guide for End Users? Learn more at http://www.sharepointshepherd.com/


So this seems to be a tough problem ... do you have a better answer to my problem ?



No comments: