OpenNETCF: RAPI.DeviceFileExists fails with directories

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

For some reason, RAPI.DeviceFileExists fails with an exception when the
file name passed in is a directory. An invalid handle is returned, and
CeGetLastError is 80, which is "File already exists."

Given that it's asking with OPEN_EXISTING, I'm not sure why it's
failing... but if we can't do anything about that, would it be worth
testing for that particular error number and returning true if it's
matched?
 
Good question, and the short answer is "beats me". :)

I'll take a look when I get back to my office next week.

-Chris
 
Jon,

Can you tell us what happens if you pass the file name with a trailing
backslash? Something like:

name = "DirectoryName\\";

rather than

name = "DirectoryName";

Paul T.
 
Paul G. Tobey said:
Can you tell us what happens if you pass the file name with a trailing
backslash? Something like:

name = "DirectoryName\\";

rather than

name = "DirectoryName";

Then I get error number 123: "The filename, directory name, or volume
label syntax is incorrect."
 
I think that we should be using CeGetFileAttributes(), not CeCreateFile()
for this operation. I think that, if you adjust the function in rapi.cs
this way, you'll get the right answer:

public bool DeviceFileExists(string RemoteFileName)

{

// check for connection

CheckConnection();

uint attr = CeGetFileAttributes( RemoteFileName );

if ( attr == 0xffffffff )

return false;

return true;

}


Paul T.
 
I'll let Chris fix it more effectively (with the same exception structure if
the failure is because of a file-not-found), but this seems to work in the
cases I tested for me.

Paul T.

Paul G. Tobey said:
I think that we should be using CeGetFileAttributes(), not CeCreateFile()
for this operation. I think that, if you adjust the function in rapi.cs
this way, you'll get the right answer:

public bool DeviceFileExists(string RemoteFileName)

{

// check for connection

CheckConnection();

uint attr = CeGetFileAttributes( RemoteFileName );

if ( attr == 0xffffffff )

return false;

return true;

}


Paul T.
 
Good call. I'm in the process of updating, fixing, etc. the RAPI stuff and
I've now added this bug fix.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Paul G. Tobey said:
I think that we should be using CeGetFileAttributes(), not CeCreateFile()
for this operation. I think that, if you adjust the function in rapi.cs
this way, you'll get the right answer:

public bool DeviceFileExists(string RemoteFileName)

{

// check for connection

CheckConnection();

uint attr = CeGetFileAttributes( RemoteFileName );

if ( attr == 0xffffffff )

return false;

return true;

}


Paul T.
 
Back
Top