当我们在SharePoint网站文档库中新建文件夹时包含了~ " # % & * : < > ? / \ { | }字符时(一共15个),会得到如下图的提示:
这在网页上使用时并没有什么问题,改个名字就好了。
不过,你可能遇到这样一种场景:
你的文件夹结构树,是从别的什么地方同步过来的,比如某第三方组织机构里,刚好有一个"A部&B部"的数据,而你们的解决方案是根据组织机构名称命名文件夹。
呃,你要做转义了。
我刚好做了一个,拿走不谢。
1 using System.Collections.Generic; 2 using System.Linq; 3 namespace SharePointCharacter 4 { 5 public static class CharacterFormatter 6 { 7 private static readonly Dictionary<string, string> Characters = new Dictionary<string, string> { 8 {"~","[td]"}, 9 {"\"","[qt]"}, 10 {"#","[hs]"}, 11 {"%","[md]"}, 12 {"&","[nd]"}, 13 {"*","[st]"}, 14 {":","[cl]"}, 15 {"<","[lt]"}, 16 {">","[gt]"}, 17 {"?","[qs]"}, 18 {"/","[sl]"}, 19 {"\\","[bs]"}, 20 {"{","[lb]"}, 21 {"|","[pp]"}, 22 {"}","[rb]"} 23 }; 24 25 public static string Encode(string content) 26 { 27 foreach (string key in Characters.Keys) 28 if (content.Contains(key)) 29 content = content.Replace(key, Characters[key]); 30 return content; 31 } 32 33 public static string Decode(string content) 34 { 35 foreach (string value in Characters.Values) 36 if (content.Contains(value)) 37 content = content.Replace(value, Characters.FirstOrDefault(x => x.Value == value).Key); 38 return content; 39 } 40 } 41 }
命名参考:
就酱。
原文:http://www.cnblogs.com/Played-Bad-SharePoint/p/5064029.html