unbelievable..?

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

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();

}

}
 
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
 
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 said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top