question

gh-2449 avatar image
0 Votes"
gh-2449 asked Jerryzy answered

C# Regex handle the special file name

How can we valid and replace the special file name character with C# ?

I can found the Regex.Replace but what's the detailed pattern ?

Thanks for any help

office-sharepoint-server-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Jerryzy avatar image
1 Vote"
Jerryzy answered

Hi @gh-2449 ,

Here is a demo for your reference to replace the special file name character using Regex.Replace:

 const string pattern = "^(\\W|_vti|_)|[^\\w]|(files|file|Dateien|fichiers|bestanden|archivos|filer|tiedostot|pliki|soubory|elemei|ficheiros|arquivos|dosyalar|datoteke|fitxers|failid|fails|bylos|fajlovi|fitxategiak)$";
 const string str = "Doc with & opr.docx";
 var regexedStr = Regex.Replace(str, pattern, string.Empty);

Reference:

RegEx to validate and replace invalid file name characters from a custom web part file upload control

Thanks
Best Regards





If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.