c# 修改程序的隐藏属性

来源:百度知道 编辑:UC知道 时间:2024/06/24 14:17:05
如何用c#修改文件的隐藏属性啊?
一个文件 不是有 隐藏和只读属性吗?

我如何通过c#实现让一个文件隐藏或者不隐藏

实现过程:

1.创建一个项目,默认窗体为Form1

2.在Form1窗体中添加OpenFileDialog控件,添加一个TextBox控件用来显示打开的文件完全路径,添加4个CheckBox控件用来让用户选择文件的属性,添加3个Button控件分别用来打开文件,修改属性和关闭窗体.

3.主要程序代码:

private void button1_Click(object send,EventArgs e)
{
this.openFileDialog1.ShowDialog();
textBox1.Text=openFileDialog1.FileName;
}

private void button2_Click(object send,EventArgs e)
{
System.IO.FileInfo f=new System.IO.FileInfo(textBox1.Text);
if(checkBox1.Checked)
{
//根据用户的选择文件的属性
f.Attributes=System.IO.FileAttributes.ReadOnly;
}
if(checkBox2.Checked)
{
f.Attributes=System.IO.FileAttributes.System;
}
if(checkBox3.Checked)
{
f.Attributes=System.IO.FileAttributes.Archive;
}
if(checkBox4.Checked)
{
f.Attributes=System.IO.FileAttributes.Hidden;
}
}

不太明白你的意思