Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:41:11+00:00 2026-05-26T10:41:11+00:00

I’m trying to implement a customization in SharePoint 2010 so that when a document

  • 0

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).

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.

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

  1. ItemAdding
  2. ItemAdded

But when I copy/paste a file into Explorer View I see the following events:

  1. ItemAdding
  2. ItemAdded
  3. ItemAdding
  4. ItemAdded
  5. ItemUpdating
  6. ItemUpdated

The result is I have two files with different names (since the Document IDs are different).

I’ve found a lot of people talking about this issue online (this 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.

This is my code that works great when using the Web upload but not when using Explorer View:

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:41:12+00:00Added an answer on May 26, 2026 at 10:41 am

    I have found that using a Visual Studio workflow allows me the most flexibility to do this. A SharePoint Designer Workflow would be simpler, but would be harder to deploy to different sites and libraries.

    After reading some good articles including this and this I have come up with this code which seems to work. It starts a workflow and waits until the document is not in a LockState and then processes the filename.

    The workflow looks like this:

    Workflow image

    And here is the code behind:

    namespace ControlledDocuments.RenameWorkflow
    {
        public sealed partial class RenameWorkflow : SequentialWorkflowActivity
        {
            public RenameWorkflow()
            {
                InitializeComponent();
            }
    
            public Guid workflowId = default(System.Guid);
            public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
    
            Boolean continueWaiting = true;
    
    
            private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void whileActivity(object sender, ConditionalEventArgs e)
            {
                e.Result = continueWaiting;
            }
    
            private void onWorkflowItemChanged(object sender, ExternalDataEventArgs e)
            {
                CheckFileStatus();
            }
    
            private void CheckFileStatus()
            {
                if (workflowProperties.Item.File.LockType == SPFile.SPLockType.None)
                {
                    continueWaiting = false;
                }
            }
    
            private void renameFile(object sender, EventArgs e)
            {
                try
                {
                    SPListItem currentItem = workflowProperties.Item;
    
                    if (currentItem["_dlc_DocId"] != null)
                    {
                        string docId = currentItem["_dlc_DocId"].ToString();
                        if (!currentItem["BaseName"].ToString().StartsWith(docId))
                        {
                            currentItem["BaseName"] = docId + currentItem["BaseName"];
                            currentItem.SystemUpdate();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Should do something useful here
                }
            }
    
        }
    }
    

    Hope this helps someone else if they have the same problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.