[英]Saving file in C#
我是 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");
function 我完全有文章中的內容。 從文章中我舉了最后一個例子。 “文件”由StreamWriter
創建。 然后它使用Serialize
將 object 轉換為 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();
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.