How to delete xml file with c#?

Asked

Viewed 19 times

-1

I am using this code to create the XML file, but I wanted to know how to delete one without having to go to the folder and delete manually.

     DataTable table = new DataTable("tbl");
        table.Columns.Add("CaminhoR1", typeof(string));
        table.Columns.Add("NomeTblR1", typeof(string));
        table.Columns.Add("ConcR1", typeof(string));
        table.Columns.Add("CaminhoR2", typeof(string));
        table.Columns.Add("NomeTblR2", typeof(string));
        table.Columns.Add("ConcR2", typeof(string));

        table.Rows.Add(textBox1.Text, textBox2.Text, comboBox1.Text, textBox4.Text, textBox5.Text, comboBox2.Text);

        dgvDadosConexao.DataSource = table;          
        table.WriteXml(@"C:\Users\Felipe\source\repos\teste\teste\conexões\" + cmbConex.Text + ".xml", XmlWriteMode.WriteSchema);
  • I still do not understand why I am being negative, if you have any problem or error in the question, can not comment no?

1 answer

0


Use the File.Delete Delete()

System.IO.File.Delete(@"C:\Users\Felipe\source\repos\teste\teste\conexões\" + cmbConex.Text + ".xml");

It usually validates if the file exists to avoid an error, but in your code as you created the file it will be there.

Stay tuned to not be using the file, or it will also generate an error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.