[英]How can I copy an xml file into a folder and hide it?
使用此代碼,我可以從Internet復制xml文件並將其保存在文件夾中。
WebClient client = new WebClient();
client.DownloadFile("http://www.studiovincent.net/list.xml", "test.xml");
代碼工作正常,但我需要隱藏test.xml文件(復制到文件夾中的文件),這樣只有當我打開“顯示隱藏文件和文件夾”時它才可見。
您需要設置文件屬性,為此使用File.SetAttributes
。 雖然我也首先使用File.GetAttributes
以便保留任何現有屬性。
string filename = "test.xml";
FileAttributes attr = File.GetAttributes(filename);
attr |= FileAttributes.Hidden;
File.SetAttributes(filename,attr);
MSDN:
http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx
File.SetAttributes( “pathToFile”,FileAttributes.Hidden)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.