Note that there are some explanatory texts on larger screens.

plurals
  1. POSharePoint 2010 Rename Document on Upload Fails in Explorer View
    primarykey
    data
    text
    <p>I'm trying to implement a customization in SharePoint 2010 so that when a document is uploaded to a library, the file name is changed to include the Document ID in the name. (I know that people shouldn't worry about file names as much any more, but we have a lot of legacy files already named and users who like to have local copies).</p> <p>I was able to implement a custom Event Receiver on the ItemAdded event that renames the file by adding the Document ID before the file name. This works correctly from the web Upload.</p> <p>The problem is with the Explorer View. When I try to add the file using WebDAV in the Explorer View, I get two copies of the file. It seems that when a file is uploaded via the Web the events that fire are</p> <ol> <li>ItemAdding</li> <li>ItemAdded</li> </ol> <p>But when I copy/paste a file into Explorer View I see the following events:</p> <ol> <li>ItemAdding</li> <li>ItemAdded</li> <li>ItemAdding</li> <li>ItemAdded</li> <li>ItemUpdating</li> <li>ItemUpdated</li> </ol> <p>The result is I have two files with different names (since the Document IDs are different).</p> <p>I've found a lot of people talking about this issue online (<a href="http://blog.techardinal.com/2009/10/20/using-sharepoint-event-handlers-to-rename-documents-nice-idea-but-no-cigar.aspx" rel="nofollow">this</a> is the best article I found). Anyone have any other ideas? Would it make more sense to do this in a workflow instead of an event receiver? I could use a scheduled job instead, but that might be confusing to the user if the document name changed a few minutes later.</p> <p>This is my code that works great when using the Web upload but not when using Explorer View:</p> <pre><code>public override void ItemAdded(SPItemEventProperties properties) { try { SPListItem currentItem = properties.ListItem; if (currentItem["_dlc_DocId"] != null) { string docId = currentItem["_dlc_DocId"].ToString(); if (!currentItem["BaseName"].ToString().StartsWith(docId)) { EventFiringEnabled = false; currentItem["BaseName"] = docId + currentItem["BaseName"]; currentItem.SystemUpdate(); EventFiringEnabled = true; } } } catch (Exception ex) { //Probably should log an error here } base.ItemAdded(properties); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload