Re: List Event Handler firing twice

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As part of my testing, I stripped down the code to the basics, but it still
gets fired twice. The code is below.

Oddly, it does not fire twice on another test machine that I have. Is there
any way it could get "installed" twice? Any way to check for that?

To install the handler, I build a .wsp file and then install it so my
handler appears as feature on my sites. Then I activate the feature on the
appropriate sites.

Should I be calling base.ItemAdded(), base.ItemUpdated, and
base.ItemDeleted()?


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Data;
using System.IO;
using Microsoft.SharePoint;

namespace MyHandler
{
public class ItemEventReceiver : SPItemEventReceiver
{

private void writeLog(string s)
{
try
{
StreamWriter writer =
File.AppendText("c:\\temp\\myHandler.txt");
writer.WriteLine(System.DateTime.Now.ToShortDateString() + "
" + System.DateTime.Now.ToShortTimeString() + ": " + s);
writer.Close();
}
catch (Exception)
{
}
}


// List item added
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
myHandler("ItemAdded", properties);
}

// List item udpated
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
myHandler("ItemUpdated", properties);
}

// List item deleted
public override void ItemDeleted(SPItemEventProperties properties)
{
base.ItemDeleted(properties);
myHandler("ItemDeleted", properties);
}

private void myHandler(string eventType, SPItemEventProperties
properties)
{

writeLog("List ID: " + properties.ListId.ToString());
writeLog("Web url: " + properties.WebUrl);
writeLog("Site ID: " + properties.SiteId);
writeLog("User login: " + properties.UserLoginName);
writeLog("User name: " + properties.UserDisplayName);
writeLog("Event type: " + properties.EventType.ToString());

if (eventType != "ItemDeleted")
{
writeLog("List column dump:");
foreach (SPField item in properties.ListItem.Fields)
{
writeLog(" DisplayName:" + item.Title + " Internal:" +
item.InternalName);
}
}
}
}
}






"Wei Lu [MSFT]" <weilu@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:u%23M9WNT5HHA.2340@xxxxxxxxxxxxxxxxxxxxxxxxx
Hello JD,

I would like to get the code you use for further troubleshooting.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.


.



Relevant Pages

  • Re: hi there, all!
    ... addressing space. ... It's not true that every data structure is twice as big. ... this user need drivers?? ... The only driver I have ever had to install ...
    (Ubuntu)
  • Re: openSUSE 11.1 Beta 1 is out
    ... download is below 100KB/s and upload is twice as fast. ... Would 10,3 upgrade to 11.1 final ok, or should I install 11.0 first, or do ...
    (alt.os.linux.suse)
  • Re: Bridge wont open
    ... I really don't want to install PS again, ... And I can open Bridge from it's own link and get to PS ... I've only reinistalled PS CS3 twice since I ... I think if I want to reinstall PS after ...
    (alt.graphics.photoshop)
  • Re: Is linux free
    ... I did it twice on the same machine. ... > downloaded and upgraded all needed drivers from third-parties etc. etc. ... > you've spent much more time than any Fedora install ever will require. ... I did not need to download any drivers, but I did have to load the driver ...
    (comp.os.linux.misc)
  • RE: Install Windows Service
    ... I’d say that when you are trying to install the service ... > private void MyInstaller_Committing ... > public override void Install ...
    (microsoft.public.dotnet.languages.csharp)