Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

asp.net mvc - How to check Read and write permissions on folder in C#

In my website i want to create a new folder and then copy some files in it and also i want to create an html file through C# code. I want to know

  1. How to check read and write permission on a folder
  2. How to create an html file on runtime in project root

Im using Asp.net MVC 2 and C#.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...