如何检查读取和写入在C#中的文件夹权限 [英] How to check Read and write permissions on folder in C#
本文介绍了如何检查读取和写入在C#中的文件夹权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网站,我想创建一个新的文件夹,然后将其复制一些文件,也是我想创建一个 HTML
到文件C#
code。我想知道
- 如何检查和读取一个文件夹的写权限
- 如何在项目的根目录创建运行HTML文件
使用im Asp.net MVC 2
和 C#
。
解决方案
如何检查和读取一个文件夹的写权限
块引用>字符串的文件夹= ...VAR的权限=新的FileIOPermission(FileIOPermissionAccess.Write,文件夹);
VAR的PermissionSet =新的PermissionSet(PermissionState.None);
permissionSet.AddPermission(许可);
如果(permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
//你必须对指定文件夹的写权限
}
如何在项目的根目录创建运行HTML文件
块引用>字符串文件= Path.Combine(使用Server.Mappath(〜/),foo.html);
File.WriteAllText(文件,< HTML><身体GT;< H1>你好< / H1>< /身体GT;< / HTML>中);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 throughC#
code. I want to know
- How to check read and write permission on a folder
- How to create an html file on runtime in project root
Im using
Asp.net MVC 2
andC#
.解决方案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>");
这篇关于如何检查读取和写入在C#中的文件夹权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文