c**t 发帖数: 2744 | 1 I was pulling my hair out while try to resolve the follow exception
using(StreamWriter sw = new StreamWriter(fileName, false))
{
sw.Write(someString);
sw.Close();
};
it's because the fileName has ':' in it!! great bug!!
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path,
Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(
String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(
Fi |
c**t 发帖数: 2744 | 2 to remove illegal characters from file name:
private static string MakeValidFileName( string name )
{
string invalidChars = Regex.Escape( new string( Path.
GetInvalidFileNameChars() ) );
string invalidReStr = string.Format( @"[{0}]", invalidChars );
return Regex.Replace( name, invalidReStr, "_" );
}
【在 c**t 的大作中提到】 : I was pulling my hair out while try to resolve the follow exception : using(StreamWriter sw = new StreamWriter(fileName, false)) : { : sw.Write(someString); : sw.Close(); : }; : it's because the fileName has ':' in it!! great bug!! : at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, : Boolean needFullPath) : at System.Security.Util.StringExpressionSet.CreateListFromExpressions(
|
a***x 发帖数: 26368 | 3 A filename cannot contain any of the following characters:
\ / : * ? " < > |
,
【在 c**t 的大作中提到】 : I was pulling my hair out while try to resolve the follow exception : using(StreamWriter sw = new StreamWriter(fileName, false)) : { : sw.Write(someString); : sw.Close(); : }; : it's because the fileName has ':' in it!! great bug!! : at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, : Boolean needFullPath) : at System.Security.Util.StringExpressionSet.CreateListFromExpressions(
|
c**t 发帖数: 2744 | 4 figured that out already
【在 a***x 的大作中提到】 : A filename cannot contain any of the following characters: : \ / : * ? " < > | : : ,
|
k*****G 发帖数: 697 | 5 Very informative, thanks for sharing. |
u***n 发帖数: 33 | 6 Thanks for sharing.
【在 c**t 的大作中提到】 : I was pulling my hair out while try to resolve the follow exception : using(StreamWriter sw = new StreamWriter(fileName, false)) : { : sw.Write(someString); : sw.Close(); : }; : it's because the fileName has ':' in it!! great bug!! : at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, : Boolean needFullPath) : at System.Security.Util.StringExpressionSet.CreateListFromExpressions(
|