Was getting the below error while uploading attachment to SharePoint document library.
string pattern = "[\\~#%&*{}/:<>?|\"-]"; string replacement = " "; Regex regEx = new Regex(pattern); string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"\s+", " ");
Helpful post
http://simplyaprogrammer.com/2008/05/importing-files-into-sharepoint.html
Hope it helps
Regex.Replace(tempFileName, “[^a-zA-Z0-9_.]+”, “”, RegexOptions.Compiled);
LikeLike