cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

Renaming a File in SharePoint Online

Hi 🙂

I am trying to rename a file in a document library on SharePoint Online, I want that when a user upload a file, a flow change it name, adding the current date and hour. I am not know the formula to add the date at the name of the file, can help me please whit information about that. Is important too that when the user upload a new document the flow don't generate a new version on the historical version document.

Im am trying whit sharepoint designer because I don't know how to create a flow in Microsoft Flows, thanks fot your helps.

🙂 😃

55 REPLIES 55
Regular Visitor

Hope someone can help since there is clearly something I'm missing. I've followed the steps in the flows but when I do a test the workflow keeps running until it times out. When I look at what's happened I get a Bad Gateway error.

My flow looks like this

Annotation on 2020-03-30 at 12-55-47.png

 

 

 

 

 

 

 

 

 

 

 

 

 

When I combine the site address with the uri, I can view the item's contents without any problems. Have I mistyped or omitted something?


Thanks,
Harry

Hi @faustocapellanj ,

I've tried to follow this post about renaming my file in SharePoint. It's been really helpful, but I'm getting the following error message:

 Capture2.PNG

 

Here is why I have:

Capture.PNG

 

When I use your recommended _api/web/lists/GetByTitle('List or Doc Library Name here')

My 'List of Doc Library Name' is 'Documents' and it returns 'SP.Data.Shared_x0020DocumentsItem'

 

I've tried using 'Documents' , 'SharedDocuments' and 'Shared_x0020Documents' instead of 'Shared%20Documents' but still getting the same error message. I wonder if you have an idea on how to get this to work?

Thanks !

Hi @izzie21 

I think your issue is that you are using the File Identifier instead of the ID property. If you look at the screenshot below, the section inside the red rectangle is expecting a number not a string.

Untitled.png

Try that and let me know.

Regards

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

@faustocapellanj any thoughts on why I'm getting an error?

Hi @harrymylo ,

 

try this, in the URI field:

  • remove the / in front of _api
Regular Visitor

I have a Folder inside my List. Anyone know how to call that folder instead of the root of the list?

 

I've tried 
_api/web/lists/GetByTitle('Documents/General')

_api/web/lists/GetByTitle('Shared%20Documents/General')

 

And no response from the API. Error I get is 
List 'Documents/General' does not exist at site with URL 'https://

 

@faustocapellanj any thoughts?

Hi @BFroc 

I think for your case, you'll have to use the GetFolderByServerRelativeUrl endpoint. The link below has done information about this endpoint. By the way, I'd test the endpoint in the browser first to make sure you can see the folder you need and then try it in Power Automate.

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-resth... 

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

MWAN_0-1592849991479.png

I followed the instructions carefully but the file name is still the original file name, not updated.  

Got an error The parameter __metadata does not exist in method GetById.  double underline before metadata, single quote in the json body

Hi @MWAN 

Looking at the screenshot you posted, the Uri parameter is missing something: web. Your Uri value is _api/lists/GetByTitle('Document Request')/Items(ID), but it should be _api/lists/web/GetByTitle('Document Request')/Items(ID). Please update it to match the one I posted and give it a try.

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Thanks

The flow finished successfully but the name not updated, name should be: EMS_Environment_Matrix-Restricted-WMF-062220-147.xls.

 

MWAN_0-1592856112696.png

 

by the way, I didn't use web in the other URIs to set permission but no issue

_api/lists/getByTitle('Document Request')/Items(insertIDhere)/roleassignments/addroleassignment(principalid=varRequesterID, roledefid=1073741827)

After I changed the method to Patch, the flow completed successfully because I included an id in the URI, which is not allowed in Post method.

Hi @faustocapellanj ,

 

I followed your advice, and was able to get to a point where the HTTP Request identifies the file, no problem, but because I have a nested folder structure, I don't know what to input for SP.Data.LISTNAMEItem in the __metadata call.

 

Using just the very last folder name SP.Data.CHILDFOLDERItem results in this, but any combination of folders doesn't work.

 

BFroc_0-1593730229179.png

BFroc_1-1593730250121.png

 

Any Ideas?

Helper IV
Helper IV

@faustocapellanj this is brilliant!  It works great.

 

Now mine has a wrinkle.  My trigger is when someone uploads and then modifies the file, and selects from a drop-down of values in a choice field.
One of the choices is "External Reviewer".  There could be several tagged with this.  The first file that runs the workflow works great, the second one doesn't, because it says the file already exists.

Anything to handle a duplicate file name with this action, like putting a 1 or 2 at the end of the file name when there are duplicates?

 

Helper III
Helper III

Hi @faustocapellanj 

I tried your solution , I am getting this error, How can I resolve this?

sabeoleonunes_0-1605531676794.png

 

Hi @sabeoleonunes 

Can you please post a screenshot of the SharePoint HTTP action to see how it is configured? I can't tell exactly what's going on from that error message.

Thanks!

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Hi @smorley 

You can try to overwrite the file, but you will need the SharePoint HTTP action. For this one, you set your Site Address and set the Method to POST. For the URI, you can do something like this: 

_api/web/GetFolderByServerRelativeUrl('document library name/folder')/Files/add(url='/folder/file.ext', overwrite=true)

Set the Headers to the following Key/Value: 

  1. Key: accept, Value: application/json;odata=verbose
  2. Key: content-type, Value: application/json;odata=verbose

And finally, set the Body to the file content. Please try that and let me know.

Fausto Capellan, Jr
Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Top Kudoed Authors
Users online (7,975)