By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,165 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,165 IT Pros & Developers. It's quick & easy.

unbelievable..?

P: n/a
Hi all,

I recently built a small prototype smart device project with C# under
VS2005 SP1, and was surprised to see that a 'trivial' statement
did not work to be able to verify the existence of a file that I had created

i.e. System.IO.File.Exists(filename)

I verified the existence of the file by getting a command prompt window and
issuing a dir command. i.e. dir c:\train.zip

Can someone please let me know what can be wrong?

Thanks,

Carlos.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

namespace mything

{

public partial class Form1 : Form

{

//private System.Windows.Forms.MainMenu mainMenu1;

string filename = @"C:\train.zip";

public Form1()

{

InitializeComponent();

}

private void DeleteDB()

{

try

{

if (System.IO.File.Exists(filename)) //does not find it %$#@!

{

System.IO.File.Delete(filename);

}

}

catch (Exception ex)

{

;

}

}

private void Form1_Load(object sender, EventArgs e)

{

DeleteDB();

}

}


Feb 2 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Your program can find the file and not be able to delete it (read-only or
ACLs). The exception handler in your example catch all and don't say
anything...

/LM
"Carlos" <ch******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi all,

I recently built a small prototype smart device project with C# under
VS2005 SP1, and was surprised to see that a 'trivial' statement
did not work to be able to verify the existence of a file that I had
created

i.e. System.IO.File.Exists(filename)

I verified the existence of the file by getting a command prompt window
and
issuing a dir command. i.e. dir c:\train.zip

Can someone please let me know what can be wrong?

Thanks,

Carlos.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

namespace mything

{

public partial class Form1 : Form

{

//private System.Windows.Forms.MainMenu mainMenu1;

string filename = @"C:\train.zip";

public Form1()

{

InitializeComponent();

}

private void DeleteDB()

{

try

{

if (System.IO.File.Exists(filename)) //does not find it %$#@!

{

System.IO.File.Delete(filename);

}

}

catch (Exception ex)

{

;

}

}

private void Form1_Load(object sender, EventArgs e)

{

DeleteDB();

}

}


Feb 3 '07 #2

P: n/a
Where are you trying to run the application? You are stating it's a smart
device project. Are you running it in the emulator? In the device? Directly
under Windows? Please note that files on your disk don't exist for the
emulator, nor for you smart device.

"Carlos" <ch******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi all,

I recently built a small prototype smart device project with C# under
VS2005 SP1, and was surprised to see that a 'trivial' statement
did not work to be able to verify the existence of a file that I had
created

i.e. System.IO.File.Exists(filename)

I verified the existence of the file by getting a command prompt window
and
issuing a dir command. i.e. dir c:\train.zip

Can someone please let me know what can be wrong?

Thanks,

Carlos.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

namespace mything

{

public partial class Form1 : Form

{

//private System.Windows.Forms.MainMenu mainMenu1;

string filename = @"C:\train.zip";

public Form1()

{

InitializeComponent();

}

private void DeleteDB()

{

try

{

if (System.IO.File.Exists(filename)) //does not find it %$#@!

{

System.IO.File.Delete(filename);

}

}

catch (Exception ex)

{

;

}

}

private void Form1_Load(object sender, EventArgs e)

{

DeleteDB();

}

}


Feb 3 '07 #3

P: n/a
Carlos wrote:
Hi all,

I recently built a small prototype smart device project with C# under
VS2005 SP1, and was surprised to see that a 'trivial' statement
did not work to be able to verify the existence of a file that I had
created

i.e. System.IO.File.Exists(filename)

I verified the existence of the file by getting a command prompt window
and issuing a dir command. i.e. dir c:\train.zip

Can someone please let me know what can be wrong?

Thanks,

Carlos.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlServerCe;

namespace mything

{

public partial class Form1 : Form

{

//private System.Windows.Forms.MainMenu mainMenu1;

string filename = @"C:\train.zip";

public Form1()

{

InitializeComponent();

}

private void DeleteDB()

{

try

{

if (System.IO.File.Exists(filename)) //does not find it %$#@!

{

System.IO.File.Delete(filename);

}

}

catch (Exception ex)

{

;

}

}

private void Form1_Load(object sender, EventArgs e)

{

DeleteDB();

}

}
Hi,

You have a blank exception handler. This is bad. Your exception handlers
should have someway of reporting what's going on, when an exception
happens. An exception happens for a reason; it's an "exceptional
circumstance" and if you're program is doing nothing about it, then you may
run into trouble when it comes to debugging.

It may be unrelated, however, is it not working because you are getting an
exception, or is it not working because you never enter the 'if' block?

--
Hope this helps,
Tom Spink

Google first, ask later.
Feb 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.