sharepoint event handler data deleted when check in

319 views Asked by At

I'm writing an eventHandler to auto add a string when a file is added to a doclib.

public override void ItemAdding(SPItemEventProperties properties)
{
    SPSite site = new SPSite("url");
    SPWeb web = site.OpenWeb("myWebSite");
    SPList list = web.Lists["DocCompteur"];

    string num = "000", chaine = "";
    int compteur = 0;
    SPListItem item = list.Items[0];
    num = item["compteur"].ToString();
    compteur = int.Parse(num);
    compteur++;
    chaine = compteur.ToString("000");
    item["compteur"] = chaine;
    item.Update();
    properties.AfterProperties["DocNumber"] = "pv" + chaine;
    //properties.ListItem.File.CheckIn("Automatic checkIn");
}

The problem is that when I add a file, I have to check in new information. If I check in, the string disappear. If I cancel, the string stay... With an image, I don't have that problem...

What's wrong with my eventHandler?

0

There are 0 answers