I am trying to get the Identifier of a file in SharePoint by its filename so I can delete it. The file came from a Form and I get the filename with:
first(body('Parse_Dust_Blown_Out_Photo_JSON'))['name']
When I use "Get files (properties only)" with a Filter Query of:
FilenameWithExtension eq '@{first(body('Parse_Dust_Blown_Out_Photo_JSON'))['name']}'
It says the file is not found.
When I don't use a Filter Query and I output the "Get files (properties only)", it shows the file is there:
[
{
"ID": 562,
"{Name}": "bruce-banner_Adam Haas",
"{FilenameWithExtension}": "bruce-banner_Adam Haas.jpg",
"{Path}": "Shared Documents/Apps/Microsoft Forms/Daily Mulch Checklist/Photo of Dust Blown Out/",
"{FullPath}": "Shared Documents/Apps/Microsoft Forms/Daily Mulch Checklist/Photo of Dust Blown Out/bruce-banner_Adam Haas.jpg",
"{IsCheckedOut}": false,
}
]
So what am I doing wrong?
@Pstork1 wrote:If you use the regular dynamic content you don't have to encode the path. But if you build the path from scratch as a string you do need to encode it or you'll get an error because it doesn't know how to handle the special characters.
I first used dynamic content to check if I input in the correct format. The path looks unencoded. Before I saw this post, I never know what was wrong. Thank you!
@Pstork1 wrote:The docs rarely discuss how to enter raw content into these fields.
Thanks to my experience as a web developer, I know `encodeURIComponent` does this job.
If you use the regular dynamic content you don't have to encode the path. But if you build the path from scratch as a string you do need to encode it or you'll get an error because it doesn't know how to handle the special characters. The docs rarely discuss how to enter raw content into these fields.
That action never says we have to encode the path.☹️
Thank you! That is so much simpler as I don't need to get the file details since I already have them. This worked great.
The file identifier is the relative path to the file, but it needs to be encoded so that all the special characters are changed to their HTML equivalents.
So if the file name is test.txt and its stored in Folder 1 of the Shared Documents library in SharePoint then the relative path is
/Shared Documents/folder 1/test.txt
Putting that inside a encodeUriComponent() provides the following output which is the file identifier.
%2FShared%20Documents%2Ffolder%201%2Ftest.txt
WarrenBelz
146,653
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional