开发者

FileIOPermission fails when there is a '~' in the path. Why?

I'm catching the following error in a publishing script (VB.开发者_运维百科Net) I'm running:

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The code that fails is:

My.Computer.FileSystem.WriteAllText(path, content, False)

It runs fine for most of the files but some have a '~' in the path and those ones are all failing. Any ideas?

Just to clarify: I am using the full path an example of the path I am having problems with is "c:/websites/xml/myfile~test.xml" the ones that work are "c:/websites/xml/myfiletest2.xml"


How are you generating path? All of these work correctly for me:

My.Computer.FileSystem.WriteAllText(Server.MapPath("~test~1.xml"), "test", False)
My.Computer.FileSystem.WriteAllText(Server.MapPath("~test2.xml"), "test", False)
My.Computer.FileSystem.WriteAllText(System.IO.Path.Combine(Server.MapPath("~"), "test~3.xml"), "test", False)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜