You are here: Home » Change a Filename using a Workflow

Change a Filename using a Workflow

Posted by scottm
No Comments »

One of the questions that has arisen in our use of SharePoint is this: “How can we automatically change the filename of a document added to a document library?”  We have PDF files that are automatically created in SQL Server Reporting Services, and we want to take advantage of the ability of SSRS to create the files and email them and SP 07 lists to receive emails and add attached documents to the list.  Unfortunately we have not been able to figure out in SSRS how to append a date to the filename, so we turned to SP Workflows to find a solution.

 

Through knowledge gained in training along with a lot of head scratching, we came up with a solution.  It may not be the best solution, but it works for us.

 

1.       Create a column in the target library, name it “Text Date” (or whatever you prefer), set it as single line of text, and calculate the value using the following expression:

=Text([Today], “yyyymmdd”) 

2.       Create a workflow.

3.       Give it a name and select the checkbox for “Automatically start this workflow when a new item is created.”

4.       Click Next.

5.       Add the Action to “Set Field in Current Item.”

6.       Click Field and select “Title.”

7.       Click Value, click the function button, and in the Field drop-down select “Name (for use in forms)”.  This will set the title as the current filename without the file extension.

8.       Add the Action to “Build Dynamic String.”

9.       Click “Dynamic String” and create it as follows using “Add Lookup” (Documents is the name of my target library):

     [%Documents:Title%]_[%Documents:Text Date%].[%Documents:Type%]

10.   Click “Variable: variable1″, “Create a new variable.” and give it a name.  I called mine “FileName”.

11.   Add the Action to “Set Field in Current Item” again.

12.   Click Field and select “Name (for use in forms).”

13.   Click Value, click the Function button, change the source to “Workflow Data”, and change the field to “Variable: FileName”.

14.   Click Finish.

 

Once the Title field has been used to build the FileName variable, it can be rebuilt using any method you see fit.  The “Text Date” field can also be calculated using any date format you wish, however special characters such as / and : cannot be used in a file name.

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>