使用XmlWriter.Create(),如何使其不覆盖正在创建的文件?

使用XmlWriter.Create(),如何使其不覆盖正在创建的文件?,xml,visual-studio-2010,visual-studio,xmlwriter,Xml,Visual Studio 2010,Visual Studio,Xmlwriter,我使用VB XmlWriter.Create()获取一个writer实例,然后编写XML,但是一旦创建了XML文件,当我第二次运行程序时,它会覆盖它创建的文件。如何让它在每次运行程序时创建一个新文件?还有一种方法,我可以将文件命名为用户输入的任何用户ID?那么,从txtConsumerID中获取文本,并将文件命名为他们在此文本框中输入的内容 末级 您每次都可以通过向文件名添加时间戳动态创建新文件名,如下所示 C:\Documents and Settings\home\Desktop\Noti

我使用VB XmlWriter.Create()获取一个writer实例,然后编写XML,但是一旦创建了XML文件,当我第二次运行程序时,它会覆盖它创建的文件。如何让它在每次运行程序时创建一个新文件?还有一种方法,我可以将文件命名为用户输入的任何用户ID?那么,从txtConsumerID中获取文本,并将文件命名为他们在此文本框中输入的内容

末级

您每次都可以通过向文件名添加时间戳动态创建新文件名,如下所示

C:\Documents and Settings\home\Desktop\Notification\uu[当前系统时间戳].xml


避免替换现有文件。

每次使用不同的文件名。
Imports System
Imports System.Xml

 Public Class Form1  

 Private Sub saveXML_Click(sender As System.Object, e As System.EventArgs) Handles
 saveXML.Click  

    Dim settings As New XmlWriterSettings()  
    settings.Indent = True  

    ' Initialize the XmlWriter.
    Dim XmlWrt As XmlWriter = XmlWriter.Create("C:\Documents and
    Settings\kck\Desktop\Notification.xml", settings)  

    With XmlWrt  

        ' Write the Xml declaration.
        .WriteStartDocument()  


        ' Write the root element.
        .WriteStartElement("PIAlertMonitor")  


        .WriteStartElement("ConsumerID")
        .WriteString(txtConsumerID.Text.ToString())
        .WriteEndElement()  

        .WriteStartElement("MaxAlerts")
        .WriteString(MaxAlerts.Text.ToString())
        .WriteEndElement()  

        .WriteStartElement("Notification")  

        .WriteStartElement("MailTo")  

        .WriteStartElement("eMail")
        .WriteString(txteMail.Text.ToString())
        .WriteEndElement()  


        ' The end of this person.
        .WriteEndElement()  

        ' Close the XmlTextWriter.
        .WriteEndDocument()
        .Close()  

    End With  

    MessageBox.Show("XML File Saved")  


End Sub