web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Deleting a file on sha...
Power Automate
Answered

Deleting a file on sharepoint

(0) ShareShare
ReportReport
Posted on by 13

I have a flow where I do an HTTP request to Sharepoint with a search query for specific files.

The returned array has the full path names of all the search results.

This is not a problem until the final step where I want to delete the files.

 

The action "Delete file" requires a File Identifier, I only have file name and file path.

I have tried assembling the File Identifier myself by using the concat expression trying both using "/" after each folder name and "%252f".

This does not work and times out on the Delete file action with the error that the file was not found.

As far as I can tell the File Identifier is nothing more than the folder name (minus site address)+ file name.

 

Is it possible to do this, if yes, how?

Categories:
I have the same question (0)
  • Verified answer
    Expiscornovus Profile Picture
    33,830 Most Valuable Professional on at

    Hi @lexxx,

     

    You can delete a file by using the X-HTTP-Method: DELETE key/value in the Headers of a SharePoint REST API request, you can combine that with the relative path of a file. By using a slice on the third '/' character (using an nthindexOf) you can retrieve that relative path from the full path value.

     

    Below is an example with the GetFileByServerRelativeUrl method.

    However, you could also use the GetFileByServerRelativePath method, that can use a decodedurl: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/supporting-and-in-file-and-folder-with-the-resourcepath-api#get-files

     

    _api/web/getfilebyserverrelativeurl('@{slice(variables('FullPath'), nthIndexOf(variables('FullPath'), '/', 3))}')

     

    nthindexof_delete.png

  • lexxx Profile Picture
    13 on at

    Hi @Expiscornovus,

    Thanks, I will definitely put this one in my toolbox.

    Another way I have figured out is to use the action get file metadata and then use the id returned from that action to delete the file using the action delete file.

     

    I have accepted your solution because it was first.

      

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 552

#2
Valantis Profile Picture

Valantis 388

#3
11manish Profile Picture

11manish 375

Last 30 days Overall leaderboard