public static string StripInvalidPathChars(string p_strPath)
{
if (String.IsNullOrEmpty(p_strPath))
return p_strPath;
Set<string> setChars = new Set<string>();
p_strPath = p_strPath.Replace("\"", "");
string strPath = Path.GetDirectoryName(p_strPath);
foreach (char chrInvalidChar in Path.GetInvalidPathChars())
setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
Regex rgxInvalidPath = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
strPath = rgxInvalidPath.Replace(strPath, "");
string strFile = Path.GetFileName(p_strPath);
setChars.Clear();
foreach (char chrInvalidChar in Path.GetInvalidFileNameChars())
setChars.Add("\\x" + ((Int32)chrInvalidChar).ToString("x2"));
rgxInvalidPath = new Regex("[" + String.Join("", setChars.ToArray()) + "]");
strFile = rgxInvalidPath.Replace(strFile, "");
return Path.Combine(strPath, strFile);
}