Hello!
I have a canvas app with a form that allows users to upload attachments. The issue is that users upload attachments that have special characters in the file name, and then they are not successfully saved to the SharePoint. Is there a way to show an error message when the file name of a chosen attachment includes a special character before it can be submitted in the app?
That worked! Thank you SO MUCH!
Hi @LindseyT ,
Assuming tha AttachmentsComponent is a regular Attachments control, the below should work:
If(
"Error" in ForAll(
AttachmentsComponent.Attachments,
If(
IsMatch(
ThisRecord.Name,
".*[\\\""<>!@#$%^&*].*"
),
"Error"
)
),
Notify("No special characters in filename please", NotificationType.Error),
<Upload file>
)
Thank you for the response! I am having an issue with the "FileName" you mention above. The datacard is called "AttachmentsComponent" and the only thing I can get to come up is "AttachmentsComponent.Attachments" but this doesn't seem to be looking at the text in the filename from what I can see. Is there a different AttachmentsComponent.XXX that I should be looking for?
Hi @LindseyT You can use IsMatch function.
ForAll(
NameOfTheAttchmentControl.Attachments As var,
If(
IsMatch(
var.Name,
"([_^+&\-\/()])",
MatchOptions.Contains
) && !IsEmpty(NameOfTheAttchmentControl.Attachments),
ClearCollect(
col_IssueInFileName,
{Name: var.Name}
)
));
If(CountRows(col_IssueInFileName)>0, Notify("Invalid Name", NotificationType.Error), UploadCode)
So, basically, I am considering that you have are allowing multiple attachments. And I am using these "([_^+&\-\/()])" characters as invalid. You can add your own characters. So, if any file name contains these character, then that file name is added into collection and if the CountRows of that collection is more than 0 then you can thrown the error.
You can have modify this code as per your requirement.
-----------------------------------------------------------------------------------------------------------------------------
I hope this helps.
Please click Accept as solution ✅ if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs up.👍
Thanks,
ANB
Hi @LindseyT ,
In this topic you can find how to detect special characters: https://powerusers.microsoft.com/t5/Building-Power-Apps/Special-Characters-IsMatch-Formula-no-longer-working/m-p/2197893
By using this in the OnSelect property of Upload button (or anything similar), you can show an error:
If(
IsMatch(FileName,".*[\\\""<>!@#$%^&*].*"),
Notify("No special characters in filename please", NotificationType.Error),
<Upload file>
)
FileName should be replaced with a reference to the control/object that has the filename and <upload file> should be replaced with the formula you currently have to upload files.
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
Super User 2025 Season 2
mmbr1606
275
Super User 2025 Season 2