我有一个测试,我正在使用它来创建示例xml数据。目前输出正被保存到我的桌面。我想要做的是将文件保存到测试项目中的文件夹,即/outputs
。有没有办法通过反射或其他方式来做到这一点?如何使用反射将输出保存到文件夹
[TestMethod]
public void ProduceSampleIndicativeData()
{
var process_serializer = new XmlSerializer(typeof(ProcessIndicativeDataType));
var sync_serailizer = new XmlSerializer(typeof (SyncIndicativeDataType));
XmlWriter process_writer = new XmlTextWriter(@"C:\Users\...\Desktop\ProcessIndicativeData.xml", new UTF8Encoding());
XmlWriter synch_writer = new XmlTextWriter(@"C:\Users\...\Desktop\SyncIndicativeData.xml",new UTF8Encoding());
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "http://www.hr-xml.org/3");
namespaces.Add("oa", "http://www.openapplications.org/oagis/9");
namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
process_serializer.Serialize(process_writer, processIndicativeData, namespaces);
sync_serailizer.Serialize(synch_writer,syncIndicativeData,namespaces);
}
我已经试过
string ProcessIndicativeDataLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"OutputFiles\ProcessIndicativeData.xml");
但这指向C:\Users\...\AppData\Local\Temp\...
当你说项目文件夹,请您是指项目存储在的目录,还是它运行的目录?我会推荐后者。 –
我指的是项目在@TonyHopkinson中运行的文件夹 –