使用此代码,我可以从Internet复制xml文件并将其保存在文件夹中.
WebClient client = new WebClient();
client.DownloadFile("http://www.studiovincent.net/list.xml", "test.xml");
Run Code Online (Sandbox Code Playgroud)
代码工作正常,但我需要隐藏test.xml文件(复制到文件夹中的文件),这样只有当我打开"显示隐藏文件和文件夹"时它才可见.
您需要设置文件属性,File.SetAttributes用于此目的.虽然我也先使用,File.GetAttributes以便保留任何现有属性.
string filename = "test.xml";
FileAttributes attr = File.GetAttributes(filename);
attr |= FileAttributes.Hidden;
File.SetAttributes(filename,attr);
Run Code Online (Sandbox Code Playgroud)
MSDN:
http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx