I am trying to delete a file when my program draws itself (Using Visual Studio 2008).

Currently using this method

public frmMainMenu()
        {
            InitializeComponent();
			File.Delete("\\Program Files\\smartdeviceproject1\\SendXML\\1.txt");
        }

The path for the file is "\Program Files\smartdeviceproject1\SendXML\1.txt"

Yet when the program is executed, breakpointing shows that the line is executed (and no errors are thrwon) but the file remains in the directory

Screen shot - http://imgur.com/F6GOu.jpg

Is it possible that this is not working because I am using the compact framwework?

Might be ur application path and deleting file path is differnt.So specify the full path to delete the file like "c:\program files\....."

The sample code you have written is working. once try again. If you don't specify the drive in the path, it will choose the drive in which OS is installed.

>Is it possible that this is not working because I am using the compact framwework?

That is not problem with CF. File.Delete() will not throws an exception event if the specified file does not exist.

Thanks guys it was the path, stupidly I allowed my workmate to name the file for me and he obviously didn't name it 1.txt

He named it 1.txt.txt

aah, the age old problem of "Hide known file extensions" :p
remember to mark the thread as solved since you have found a solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.