I have a situation where users have uploaded several files but without any naming convention. So some of the file names are in upper case while some are in lower case . So Now I have to build a script that can read the file name from document library and then change the format to following convention: First letter of the word must be in caps and remaining letters in lower case. For example, if a file name is "construction monthly reports" or "CONSTRUCTION MONTHLY REPORTS" then it should be renamed to following: "Construction Monthly Reports".

Is this possible to do by leveraging some sort of a script? I am working with SharePoint online. If someone has come across this situation, can you please provide the solution you took. For now the app should be able to perform this change for all existing files, in future, whenever a file is uploaded then it must be renamed as per this rule.

Can someone help with a solution (Workflow, CSOM, JS etc.), if powershell is a solution then I will go with that as well. thanks in advance.

enter image description here

enter image description here enter image description here

1 Answer 1


You are in Online so I created a Flow which will do the work :) You can create another one, which will be started manualy and fix all existing documents, because I created it as for the new ones...

In SPO Library click on Flow and click Create a flow: enter image description here

Click See more and select When a new file is added in SharePoint, complete a custom action:

enter image description here

Here is the flow, first create variables:

Name - Array - Value: split(triggerBody()?['{FilenameWithExtension}'], ' ')

enter image description here

CorrectName - String - Value: Empty

enter image description here

Working - String - Value: Empty

enter image description here

Create Apply to Each - Value: variables('Name')

Set Variable - Working - Value: Current Item (will be displayed in Dynamic Content)

Append to string variable - CorrectName - Value: concat(' ', concat(toUpper(substring(variables('Working'),0,1)),toLower(substring(variables('Working'),1,add(length(variables('Working')),-1)))))

enter image description here

Set variable - Working - Value: substring(variables('CorrectName'),1,add(length(variables('CorrectName')),-1))

Send an HTTP request to SharePoint:

  • You need to rename in URI List by Title - My is Migration
  • You need to rename in Body: SP.Data.MigrationItem to yourItem (LibraryItem cause Migration is my library)

    Method: POST
    Uri: _api/web/lists/GetByTitle('Migration')/items(@{triggerBody()?['ID']})
          Content-Type: application/json;odata=verbose
          IF-MATCH: * 
          X-HTTP-Method: MERGE
    Body: {'__metadata':{'type':'SP.Data.MigrationItem'},'FileLeafRef':'@{variables('Working')}','Title':'@{variables('Working')}'}

enter image description here

Whole Flow look like this:

enter image description here

Here is my test:


enter image description here

After Flow:

enter image description here

I hope you will like it! :) Zdeněk

  • Thanks a lot for the answer. Wanted to confirm, in regards to the existing documents, should I just replaced the file created trigger with Manually trigger a flow trigger and keep the other action same as is, right? Thanks again.
    – mdevm
    Commented Jan 27, 2019 at 2:16
  • Yes, you just do manually triger, at start load all files from this library (SharePoint - Get files (Properties Only)) and in Apply to Each, do this flow (constants must be initialized at start) Commented Jan 27, 2019 at 9:05
  • in this case you will need edit the Values where are triggerbody, which I post here, cause it will be a little different. There will be the foreach item instead. Commented Jan 27, 2019 at 9:10
  • I am getting an error: "The property '__metadata' does not exist on type 'SP.Data.Corporate_x0020_DocumentsItem'. My library name is "Corporate Documents" so that's the issue I guess, the http action is failing.
    – mdevm
    Commented Jan 27, 2019 at 15:28
  • I have added some screenshots in question description of the flow run and my http re action, please take a look.
    – mdevm
    Commented Jan 27, 2019 at 15:45

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.