[英]Saving file in C#
I'm new to programming in C#.我是 C# 编程新手。 I want to create and download an
xml
file.我想创建并下载一个
xml
文件。 I found this artical on creating the xml.我在创建 xml 时发现了这篇文章。 I followed it and it works perfect.
我跟着它,它工作得很好。 But I can't figure out how to save the file to my computer.
但我不知道如何将文件保存到我的电脑上。 I think it has to be inplemented someware here:
我认为它必须在这里实现一些:
public static void Main()
{
// Read and write purchase orders.
Test t = new Test();
t.CreatePO("po.xml");
//I think here the file is ready to dowload
t.ReadPO("po.xml");
}
As for the t.CreatePO("po.xml");
至于
t.CreatePO("po.xml");
function I have exactly whats in the artical. function 我完全有文章中的内容。 From the artical I took the last example.
从文章中我举了最后一个例子。 The 'file' is created by a
StreamWriter
. “文件”由
StreamWriter
创建。 Then it converts an object to a XML by using Serialize
.然后它使用
Serialize
将 object 转换为 XML 。
Any step in the right direction will help!朝着正确方向迈出的任何一步都会有所帮助!
For your question, you want to save the file to your computer.对于您的问题,您希望将文件保存到您的计算机。
You could try the following code to get it.您可以尝试以下代码来获取它。
// Creates an instance of the XmlSerializer class;
// specifies the type of object to serialize.
XmlSerializer serializer =
new XmlSerializer(typeof(PurchaseOrder));
//We can use absolute paths to store it anywhere on the computer
string xmlPath = @"D:\Task\";
TextWriter writer = new StreamWriter(Path.Combine(xmlPath,filename));
PurchaseOrder po = new PurchaseOrder();
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.