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 353 views
353 views asked Mar 15, 2015 by avibootz
3 answers 267 views
267 views asked Mar 16, 2015 by avibootz
1 answer 146 views
146 views asked Sep 5, 2014 by avibootz
1 answer 139 views
2 answers 161 views
2 answers 161 views
...