gpt4 book ai didi

c# - 如何将 xml 文件复制到文件夹中并隐藏它?

转载 作者:行者123 更新时间:2023-11-30 20:03:38 24 4
gpt4 key购买 nike

使用这段代码,我可以从互联网上复制一个 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

关于c# - 如何将 xml 文件复制到文件夹中并隐藏它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14524067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com