Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top