使在C#中的文件写入的最佳方法 [英] Best way to make a file writeable in c#

查看:141
本文介绍了使在C#中的文件写入的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置标志,导致只读复选框出现,当你右键点击一个文件\属性。

I'm trying to set flag that causes the "Read Only" check box to appear when you right click \ Properties on a file.

谢谢!

推荐答案

有两种方式:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
fileInfo.IsReadOnly = true/false;

// Careful! This will clear other file flags e.g. FileAttributes.Hidden
File.SetAttributes(filePath, FileAttributes.ReadOnly/FileAttributes.Normal);

上的FileInfo的IsReadOnly属性实质上确实比特翻转你将不得不在第二种方法人工做

The IsReadOnly property on FileInfo essentially does the bit-flipping you would have to do manually in the second method.

这篇关于使在C#中的文件写入的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆