×

VB.Net Programs

VB.Net program to create an empty XML file

By Nidhi Last Updated : October 13, 2024

How to create an empty XML file in VB.Net?

Here, we will demonstrate the use of XmlTextWriter class to create an empty XML file on the hard disk drive.

Program/Source Code:

The source code to create an empty XML file is given below. The given program is compiled and executed successfully.

VB.Net code to create an empty XML file

'VB.NET program to create an empty XML file.

Imports System.Xml
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        Dim xmlFile As XmlTextWriter

        xmlFile = New XmlTextWriter("Sample.xml", Encoding.UTF8)

        Console.WriteLine("Sample.xml file created successfully")

        xmlFile.Flush()
        xmlFile.Close()
    End Sub
End Module

Output

Sample.xml file created successfully
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a function Main(), and here we imported the System.Xml namespace to use XmlTextWriter class.

The Main() function is the entry point for the program. In the Main() function, we created the object of XmlTextWriter class to create the "Sample.xml" file. After that we used Flush() and Close() function to close the "Sample.xml" file properly.

VB.Net File Handling Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.