gpt4 book ai didi

c# - X文档文件名

转载 作者:行者123 更新时间:2023-11-30 14:02:28 25 4
gpt4 key购买 nike

有没有办法从 XDocument 对象本身检索 XDocument 保存的路径(文件名)?

我的意思是在我已经保存 XDocument 对象之后获取保存的路径。像这样:

XDocument xDoc = new XDocument();
xDoc.Save(@"C:\Temp\MyXmlDoc.xml");

string str = xDoc.SavedPath() // <== something like this

最佳答案

如果加载 XDocument从文件中,BaseUri属性将包含文件名。如 MSDN 中所述:

Sometimes the XmlReader has the base URI, and sometimes it does not. For instance, when loading from a file, the XmlReader knows the base URI, but when reading from an XmlReader that was created because of calling the Parse method, there is no possibility of the XmlReader reporting a base URI; the XML was in a string.

但是,保存文档时不会设置,仅在加载操作期间设置。因此,如果您需要知道保存路径,则需要在保存时独立于 XDocument 实例进行存储。

关于c# - X文档文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5898583/

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