在我的网站中,我想创建一个新文件夹,然后在其中复制一些文件,我还想通过html
代码创建一个C#
文件。我想知道
我正在使用Asp.net MVC 2
和C#
。
答案 0 :(得分:15)
如何检查文件夹的读写权限
string folder = ...
var permission = new FileIOPermission(FileIOPermissionAccess.Write, folder);
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
// You have write permission for the given folder
}
如何在项目根目录
中的运行时上创建html文件
string file = Path.Combine(Server.MapPath("~/"), "foo.html");
File.WriteAllText(file, "<html><body><h1>Hello</h1></body></html>");
答案 1 :(得分:1)
为什么不使用App_Data,其中ASP.NET应用程序的标识自动具有读写权限?