How to delete file if exists in C#

1 Answer

0 votes
using System;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (File.Exists(@"D:\data.txt")) 
            {
                File.Delete(@"D:\data.txt");
            }


        }
    }
}



/*
 * run:
 * 
 * 
 */

 



answered Jul 27, 2023 by avibootz

Related questions

4 answers 523 views
523 views asked Mar 15, 2015 by avibootz
3 answers 411 views
411 views asked Mar 16, 2015 by avibootz
1 answer 229 views
229 views asked Sep 5, 2014 by avibootz
1 answer 227 views
2 answers 283 views
2 answers 268 views
...