Sunday, August 7, 2011

SharePoint Escape Characters


How sharepoint handles escape characters? Sharepoint internally replace escape character with some code like, if you are creating field with space in that name e.g. “my column” then sharepoint replace space with _x0020_ e.g “my_x0020_column”.
Following are the complete escape characters and their code in Sharepoint.
Blank space: _x0020_
Underscore: _x002d_
Dash: _x0027_
Here is the Format:
_x00[the escape code]_
Char Code
[space] 20
3E
# 23
% 25
{ 7B
} 7D
| 7C
\ 5C
^ 5E
~ 7E
[ 5B
] 5D
` 60
; 3B
/ 2F
? 3F
: 3A
@ 40
= 3D
& 26
$ 24
 public static String GetFieldNamebyEscapeCharacter(String sName)
        {
            String sReturn = sName;
            String sChar = "_x00{0}_";
            sReturn = sReturn.Replace("_", String.Format(sChar, "2d"));
            sReturn = sReturn.Replace(" ", String.Format(sChar, "20"));
            sReturn = sReturn.Replace("-", String.Format(sChar, "27"));
            sReturn = sReturn.Replace("#", String.Format(sChar, "23"));
            sReturn = sReturn.Replace("%", String.Format(sChar, "25"));
            sReturn = sReturn.Replace("{", String.Format(sChar, "7B"));
            sReturn = sReturn.Replace("}", String.Format(sChar, "7D"));
            sReturn = sReturn.Replace("|", String.Format(sChar, "7C"));
            sReturn = sReturn.Replace("\\", String.Format(sChar, "5C"));
            sReturn = sReturn.Replace("^", String.Format(sChar, "5E"));
            sReturn = sReturn.Replace("~", String.Format(sChar, "7E"));
            sReturn = sReturn.Replace("[", String.Format(sChar, "5B"));
            sReturn = sReturn.Replace("]", String.Format(sChar, "5D"));
            sReturn = sReturn.Replace("`", String.Format(sChar, "60"));
            sReturn = sReturn.Replace(";", String.Format(sChar, "3B"));
            sReturn = sReturn.Replace("/", String.Format(sChar, "2F"));
            sReturn = sReturn.Replace("?", String.Format(sChar, "3F"));
            sReturn = sReturn.Replace(":", String.Format(sChar, "3A"));
            sReturn = sReturn.Replace("@", String.Format(sChar, "40"));
            sReturn = sReturn.Replace("=", String.Format(sChar, "3D"));
            sReturn = sReturn.Replace("&", String.Format(sChar, "26"));
            sReturn = sReturn.Replace("$", String.Format(sChar, "24"));
            return sReturn;
        }

No comments: