C# 用C保存文件#

C# 用C保存文件#,c#,.net,visual-studio,C#,.net,Visual Studio,我不熟悉C语言编程。我想创建并下载一个xml文件。我找到了一篇关于创建xml的文章。我遵循它,它工作得很完美。但是我不知道如何将文件保存到我的计算机上。我认为它必须在这里实现: 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 dow

我不熟悉C语言编程。我想创建并下载一个
xml
文件。我找到了一篇关于创建xml的文章。我遵循它,它工作得很完美。但是我不知道如何将文件保存到我的计算机上。我认为它必须在这里实现:

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");
}
至于
t.CreatePO(“po.xml”)函数我完全掌握了文章中的内容。
从这篇文章中,我举了最后一个例子。
“文件”由
StreamWriter创建。然后,它使用
序列化
将对象转换为XML


朝着正确方向迈出的任何一步都会有帮助

对于您的问题,您希望将文件保存到计算机中

您可以尝试以下代码来获得它

// 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();
结果:


您的目标是什么:Winforms、WPF、ASP。。?您应该始终正确标记您的问题,以便人们可以在问题页面上看到它@TaW我正在使用
.net
框架。我还在问题中添加了标签。@Tim567我相信他的意思是你的标签所能提供的信息不够详细。如果您提供更多信息,例如
WinForm
ASP.Net Api
,会更好。至于您的问题,要下载文件,您可以1)直接从服务器下载文件。或者2)从serve获取内容,然后将其写入本地文件。我想关键的问题是:(1)t.CreatePO(“po.xml”)
做什么?看起来它创建了一个文件
po.xml
,但是它在哪里创建文件呢?(2) “下载”是什么意思?@dumetrulo关于你的第一点,请看我在问题中提到的文章。第二点:我想将
xml
保存为计算机上的文件。这很有效!只需添加
writer.Write(xmlString)就是这样!谢谢