IDicker

We need to rename documents based on the version number.

I created a custom content type for this, and added it to a document library. I then created a custom site policy and attached it to the content type. The Register method for the Policy sets up an EventReceiver.

I have tried catching the itemadding, checkingin, checkin, update, updating events.

The code for the event handler is:

DisableEventFiring();

base.ItemUpdating(properties);

SPListItem li = properties.ListItem;

string prefix = GetPrefixForPolicyInstance(li);

SPFile file = li.File;

int versionId = file.MajorVersion;

file.Item["Name"] = prefix + versionId.ToString() + file.Name;

file.Item.Update();

When I do this the filename gets updated - but then word 2007 complains that the file no longers exists - some sort of mismatch in that it saved A but the data back is B.

How can I do what I need to do



Re: SharePoint - Enterprise Content Management How to rename a document during checkin to enforce rules?

RedOct

hi,

could you please tell me what kind of project & the classes i need to start up with to put this code. i'm relatively new to sharepoint stuffs..





Re: SharePoint - Enterprise Content Management How to rename a document during checkin to enforce rules?

Doc DH

My needs are pretty much alike you example. I've solved this in almost the same way you explained.

First, you have too do this when the file is added, that is use the EventReciever: ItemAdded.

Second, when you add a file, the filename actually is in the list.

Here is a listing where I rename a added file with a static prefix and the ID number of the list:

namespace ChangeName
{
public class ChangeNameHandler : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
DisableEventFiring();
base.ItemAdded(properties);
SPListItem li = properties.ListItem;
int listID = li.ID;
li["Name"] = "PREFIX" + listID.ToString();
li.Update();
}
}
}

Good luck bro!