SharePoint文档库文件夹特殊字符转义

当我们在SharePoint网站文档库中新建文件夹时包含了~ " # % & * : < > ? / \ { | }字符时(一共15个),

或者以.开头或者结束,或者包含连续的.(加上.16个)

会得到如下图的提示:

这在网页上使用时并没有什么问题,改个名字就好了。

不过,你可能遇到这样一种场景

你的文件夹结构树,是从别的什么地方同步过来的,比如某第三方组织机构里,刚好有一个"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            {".","[dt]"}
24         };
25 
26         public static string Encode(string content)
27         {
28             foreach (string key in Characters.Keys)
29                 if (content.Contains(key))
30                     content = content.Replace(key, Characters[key]);
31             return content;
32         }
33 
34         public static string Decode(string content)
35         {
36             foreach (string value in Characters.Values)
37                 if (content.Contains(value))
38                     content = content.Replace(value, Characters.FirstOrDefault(x => x.Value == value).Key);
39             return content;
40         }
41     }
42 }
View Code

 

命名参考:

就酱。

 

转载于:https://www.cnblogs.com/Played-Bad-SharePoint/p/5064029.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值