How to generate a valid SharePoint FileName
SharePoint imposes several restrictions for the filenames. To get the details of all these restrictions, please check this support article from Microsoft. I have created a utility function to convert a given string to a valid SharePoint filename. This function is valid for SharePoint 2003, 2007 and 2010. Here you go
public string ConvertToValidSharePointFileName(string originalFileName) { char[] InvalidFilenameCharacters = new[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '#', '{', '}', '%', '~','&' }; string[] InvalidFileNameStrings = new[] { ".files", "_files", "-Dateien", "_fichiers", "_bestanden","_file", "_archivos", "-filer", "_tiedostot", "_pliki", "_soubory","_elemei", "_ficheiros", "_arquivos", "_dosyalar", "_datoteke","_fitxers", "_failid", "_fails", "_bylos", "_fajlovi", "_fitxategiak"}; string validSharePointFileName = originalFileName; //Remove Invalid characters validSharePointFileName = validSharePointFileName.Remove(InvalidFilenameCharacters); //Remove consecutive periods(..) while (validSharePointFileName.Contains("..")) { validSharePointFileName = validSharePointFileName.Replace("..", "."); } //Remove reserved words from end foreach (string s in InvalidFileNameStrings) { if (validSharePointFileName.EndsWith(s)) { if (validSharePointFileName.Length > s.Length) { validSharePointFileName = validSharePointFileName.Substring(0, validSharePointFileName.Length - s.Length); } } } //Remove period (.) at end if (validSharePointFileName.EndsWith(".")) { validSharePointFileName = validSharePointFileName.Remove(validSharePointFileName.Length - 1, 1); } //Remove period (.) at end if (validSharePointFileName.StartsWith(".")) { validSharePointFileName = validSharePointFileName.Remove(0, 1); } return validSharePointFileName; }
2 Responses to “How to generate a valid SharePoint FileName”
Comment from User
Time September 26, 2013 at 6:05 am
Fix in source ‘<‘, ‘>’, ‘&’ to ”, ‘&’.
cheap levitra online pill prescription ultram cliff database essay free note paper sociology term go here https://caberfaepeaks.com/school/help-on-colleg-essays/27/ online propecia prescription viagra manufacturing plant see url essay questions about fairy tales example business plan presentation powerpoint source site dove comprare viagra farmacia best term paper writing service reviews casting below elbow prosthesis nitric oxide and viagra professional assignment writer for hire au is cialis sold at walmart dissertation intro conclusion https://reprosource.com/hospital/alli-for-sale/72/ cipro dosing information http://hyperbaricnurses.org/6449-viagra-price-at-altairulit-org/ https://sigma-instruments.com/viagra-kaufen-deutschland-apotheke-15456/ https://homemods.org/usc/essay-on-the-renaissance/46/ herex sildenafil citrato https://home.freshwater.uwm.edu/termpaper/coursewokrs/7/ do diatoms go through essay cuales son las mejores marcas de viagra https://chfn.org/fastered/seroquel-forum/36/ https://online.bentley.edu/medschool/cuenta-cialis-puedo-tomar/10/ dissertation meaning in marathi forum centro medico polispecialistico san benedetto del tronto enter site how to prepare research report Comment from Jose Dias
Time April 10, 2013 at 2:23 pm
Hi,
what would be your for best-practice on how to use this function.
Is it something that can be added into the
SharePoint File (Bilk-)Upload-Process?
Thanks in advance for your support!
Best regards,
José