0

I have multiple users uploading a filled out request form template into a document library. The template has a generic name and I want a new copy of the file in the library as each user uploads theirs. I am trying to set this up, but each time I try to add the file (after there is already a copy in the library), it overwrites the existing, OR if I uncheck the option to overwrite, it throws an error saying that a file with that name already exists. I would like each file to be renamed per below. Is there a way to make SP create copies of docs with updated names instead of overwriting?

Example: Template.docx Template(2).docx Template(3).docx, etc, etc...

2

I have a similar situation with some order entry processes.

I save the template in a document library, and have my users use a button to request a new spreadsheet (instead of having them do it on their own).

When they click the 'create new ..' button, I get a unique name using the time, insert the document into the library, and then open the document for them to edit.

All they then have to do is save.

This function uses SPServices and is specific to an Excel file (and using the current user name as the document name), but there should be similar functionality in REST or SP2013 workflows that can access web services.

 function addNew2(linkType) {

    var d = new Date();
    var dTime = d.format('_MMddHHmmss');

    var docName = cu["Title"]+ dTime;
    // note that this new doc is linked to the template, but we hide that
    // message on the property forms so the user doesn't see it.
   $().SPServices({
         operation: "CopyIntoItemsLocal",
         async: false,
         SourceUrl: window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl + "/Shared%20Documents/template.xlsm",
         DestinationUrls: [window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl +  "/SampleOrders/" + docName + ".xlsm"], 
         completefunc: function(xData, Status) {
           // alert("Status=" + Status + " XML=" + xData.responseXML.xml);  
         }
   });

    editDocumentWithProgID2(window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl + '/SampleOrders/' + docName + ".xlsm", 
    '', 
    'SharePoint.OpenDocuments', '0', 
    window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl, '0')  ;
   }
3

There are below options which comes in my mind to handle your issue. (Please note I have not tried any of this).

  1. Custom Webpart/App

If programming is option then create a custom webpart/app to upload document in document library. This will give you control to change the name of file before uploading.

  1. Custom event receiver

This will also required programming knowledge. As soon as any user uploads a document in document library, give a unique name to file. Use ItemAdded event to rename the file using SpFile.MoveTo()

For more information: Change file name in Event Handler ItemAdding

  1. Drop off library

Its purpose is to automatically route documents from a drop off library to the appropriate location (another document library) based on content types.

Drop off library have option to handle duplicate files. There is setting which you can check, which adds random character to the name of duplicate file to make it unique.

For more information on Drop off library: Drop Off Library Setup Guide

Similar question asked before which may help:

  1. How to automatically save new file into document library with a unique name or ID?
  2. Two different documents with same name become one
  3. Sharepoint- Client Object Model - Javascript - How to check if a particular file with same name exists in a document library folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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