2

I need to rename document after creating from MS Office Word.

I've created EventReceiver OnItemAdded where I am trying to change "FileLeafRef" field:

public override void ItemAdded(SPItemEventProperties properties)
{
   this.EventFiringEnabled = false;
   properties.ListItem[SPBuiltInFieldId.FileLeafRef] = "SampleName.docx";
   properties.ListItem.Update();
   this.EventFiringEnabled = true;
   base.ItemAdded(properties);
}

Result: The file is locked for exclusive use by .

When I am trying SystemUpdate() File is checked out after saving, but I do not need to check out file.

Where I am wrong?

1 Answer 1

0

Check out this article on the subject:

http://blogs.msdn.com/b/sowmyancs/archive/2008/10/02/programmatically-rename-a-file-inside-a-sharepoint-document-library.aspx

Your issue is that the field FileLeafRef is a calculated column and as such is not writeable. What you need to do is change the actual name of the file itself and allow FileLeafRef to compose the URL itself. As noted in the article, you will probably need to check the file out and then back in (and of course update it against the library).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.