Created
May 18, 2010 13:11
-
-
Save program247365/404971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Folder Name (For Preparing Folders to be Moved to SharePoint) | |
/// You cannot use the following characters anywhere in a folder name or a server name: ~ # % & * { } \ : < > ? / | " | |
/// Cannot be longer than 128 characters | |
/// You cannot use the period character consecutively in the middle of a folder name | |
/// You cannot use the period character at the end of a folder name | |
/// You cannot start a folder name with the period character | |
/// </summary> | |
/// <param name="folderName">vomit</param> | |
/// <returns>vomit</returns> | |
public static string CleanFileFolderName(string folderName) | |
{ | |
//take out all wierd characters in the names that sharepoint/windows would vomit on. | |
folderName = folderName | |
.Replace("", "") | |
.Replace("\"", "") | |
.Replace("#", "") | |
.Replace("%*", "") | |
.Replace("&", "and") | |
.Replace("*", "") | |
.Replace("<", "") | |
.Replace(">", "") | |
.Replace("?", "") | |
.Replace("\\", "") | |
.Replace("/", "") | |
.Replace("{", "") | |
.Replace("|", "") | |
.Replace("}", "") | |
.Replace("~", "") | |
.Replace("..", "."); //cannot use the period character consectively in the middle of a folder name | |
if (folderName.StartsWith(".")) | |
folderName = folderName.Replace(folderName.Substring(0, 1), folderName); //you cannot start a folder with the period character | |
if (folderName.EndsWith(".")) | |
folderName = folderName.Replace(folderName.Substring(folderName.Length, 1), folderName); //you cannot end a folder with the period character | |
int largestSubFolderLength = 21; | |
if (folderName.Length > 128 - largestSubFolderLength) | |
folderName = folderName.Substring(0, 128 - largestSubFolderLength); | |
int count = folderName.Length; | |
return folderName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment