设置文件属性 [英] setting file attributes
本文介绍了设置文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个简单的Windows窗体应用程序,它需要在c:\program files \中创建一个文本文件...但是我一直遇到使文件隐藏的麻烦。我试过了
i''m working on a simple windows form application that needs to create a text file in c:\program files\... but i keep running into troubles making the file hidden. I tried
File.SetAttributes(filePath, File.GetAttributes(filePath) | FileAttributes.Hidden)
但它似乎没有工作。请有人帮我提供正确的代码。
but it didn''t seem to work. Pls can someone help me with the correct code for this.
推荐答案
http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx [ ^ ]
http://www.csharp-examples.net/file-attributes/ [ ^ ]
http://net-informations.com/csprj/file/file-attributes.htm [ ^ ]
http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx[^]
http://www.csharp-examples.net/file-attributes/[^]
http://net-informations.com/csprj/file/file-attributes.htm[^]
检查所考虑的文件是不是锁定并有权使用它。
check the considered file is not locked and privilege to work with it.
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
private static void SetFileToHidden(string filePath)
{
var attrs = File.GetAttributes(filePath);
File.SetAttributes(filePath, attrs | FileAttributes.Hidden);
}
这篇关于设置文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文