Tuesday, March 11, 2014

Make valid file name for Sharepoint

Hello, We are some times facing problem to validate a file name for sharepoint for special characters. Below is the code for the same :) private string GetValidFileName(string currentFileName) { //this.currentFileNameTemp = currentFileName; string fileName = currentFileName; //special chars not allowed in filename string specialChars = @"\/:*?""<>^|#%&{}~"; //Replace special chars in raw filename with empty spaces to make it valid Array.ForEach(specialChars.ToCharArray(), specialChar => fileName = fileName.Replace(specialChar, ' ')); fileName = fileName.Replace(" ", string.Empty); return fileName; }

No comments: