How to check read and write permission on a folder
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
}
How to create an html file on runtime in project root
string file = Path.Combine(Server.MapPath("~/"), "foo.html");
File.WriteAllText(file, "<html><body><h1>Hello</h1></body></html>");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…