Jump to content
Bill Meyer

problem with file attributes

Recommended Posts

I am calling the DevExpress ExportGridToXLSX, and it produces the spreadsheet no problem. The difficulty comes after, as I want to open it in FlexCel to insert a header, it fails. I have this snippet:
  ExportGridToXLSX(fn, grdMain);
  b := FileExists(fn);
I have tested in a small program, and FileExists returns True. But in WOMS, form the Daily Grid, it returns false. In both cases, the xlsx file opens in Excel without a problem.
 
Going deeper, the failure of FileExists is because the call it makes to GetFileAttributes returns INVALID_FILE_ATTRIBUTES.
 
Any thoughts?
 

Share this post


Link to post

INVALID_FILE_ATTRIBUTES is what you'd get if the file did not exist. It doesn't mean there is a problem with the file attributes. 

Edited by David Heffernan

Share this post


Link to post
1 minute ago, David Heffernan said:

INVALID_FILE_ATTRIBUTES is what you'd get if the file did not exist. It doesn't mean there is a problem with the file attributes. 

Agreed. I did not word the title well.

However, the file does exist, and the result from FileExists is incorrect as its call to GetFileAttributes returns INVALID_FILE_ATTRIBUTES.

Adding a delay as a check accomplishes nothing, it is not a matter of the write not having completed.

Share this post


Link to post
26 minutes ago, David Heffernan said:

INVALID_FILE_ATTRIBUTES is what you'd get if the file did not exist. It doesn't mean there is a problem with the file attributes. 

GetFileAttributes() can return INVALID_FILE_ATTRIBUTES for a number of different reasons, not just because the file does not exist.  You have to use GetLastError() to differentiate the actual cause.

Edited by Remy Lebeau

Share this post


Link to post
25 minutes ago, Bill Meyer said:

However, the file does exist, and the result from FileExists is incorrect as its call to GetFileAttributes returns INVALID_FILE_ATTRIBUTES.

Then you likely don't have access to the file, or at least don't have permissions to ask the filesystem for its attributes.  You need to call GetLastError() to find out why GetFileAttributes() is failing.

 

Edited by Remy Lebeau

Share this post


Link to post
31 minutes ago, Remy Lebeau said:

Then you likely don't have access to the file, or at least don't have permissions to ask the filesystem for its attributes.  You need to call GetLastError() to find out why GetFileAttributes() is failing.

 

This app created the file. A few lines later, it looks for the file, and GetLastError reports 2: ERROR_FILE_NOT_FOUND

But the file exists, in that same location. It is openable in Excel, and can be resaved from Excel. And after that, I still get a fail on FileExists().

 

 
 

Share this post


Link to post
50 minutes ago, Remy Lebeau said:

GetFileAttributes() can return INVALID_FILE_ATTRIBUTES for a number of different reasons, not just because the file does not exist.  You have to use GetLastError() to differentiate the actual cause.

Correct. 

 

Also correct, if the file does not exist, then INVALID_FILE_ATTRIBUTES is what you'd get. Which is what I said. 

Share this post


Link to post
16 minutes ago, David Heffernan said:

Correct. 

 

Also correct, if the file does not exist, then INVALID_FILE_ATTRIBUTES is what you'd get. Which is what I said. 

But as I wrote above, the file clearly does exist.

Share this post


Link to post
15 minutes ago, Bill Meyer said:

But as I wrote above, the file clearly does exist.

I'm not disputing that. All I was trying to say, all along, is that the issue is not to do with file attributes. 

Share this post


Link to post
4 hours ago, Bill Meyer said:

This app created the file. A few lines later, it looks for the file, and GetLastError reports 2: ERROR_FILE_NOT_FOUND

Then you likely did not create the file where you are expecting.  Are you using relative paths, for instance?  What is the actual value of your fn variable?

4 hours ago, Bill Meyer said:

But the file exists, in that same location.

The filesystem does not lie about file existence.  If it says a file does not exist, then it really does not exist.  Double-check your input.

4 hours ago, Bill Meyer said:

It is openable in Excel, and can be resaved from Excel. And after that, I still get a fail on FileExists()

With the same ERROR_FILE_NOT_FOUND error?  I suggest you use SysInternals Process Monitor to see EXACTLY which file path your app is REALLY trying to access, and make sure it matches your expectation.

Share this post


Link to post
9 hours ago, Remy Lebeau said:

With the same ERROR_FILE_NOT_FOUND error?  I suggest you use SysInternals Process Monitor to see EXACTLY which file path your app is REALLY trying to access, and make sure it matches your expectation.

Here is a selection from the Process Monitor log which shows the last few entries of the file write activity, and the subsequent failure to find the file:
"Time of Day","Process Name","PID","Operation","Path","Result","Detail"
"5:54:48.3007155 AM","MediaOffice.exe","7476","WriteFile","T:\TestSheet.xlsx","SUCCESS","Offset: 17,179, Length: 46"
"5:54:48.3007203 AM","MediaOffice.exe","7476","WriteFile","T:\TestSheet.xlsx","SUCCESS","Offset: 17,225, Length: 19"
"5:54:48.3007257 AM","MediaOffice.exe","7476","WriteFile","T:\TestSheet.xlsx","SUCCESS","Offset: 17,244, Length: 22"
"5:54:48.3010912 AM","MediaOffice.exe","7476","CloseFile","T:\TestSheet.xlsx","SUCCESS",""
"5:54:48.3363273 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
"5:54:48.3363673 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
"5:54:48.3363977 AM","MediaOffice.exe","7476","CreateFile","T:\TestSheet.xls","NAME NOT FOUND","Desired Access: Write Attributes, Synchronize, Disposition: Open, Options: Synchronous IO Non-Alert, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"5:54:48.3364372 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""

And here, a sample of the activity which appears to be from the FileExists() call:
"Time of Day","Process Name","PID","Operation","Path","Result","Detail"
"5:54:48.3639990 AM","MediaOffice.exe","7476","CloseFile","C:\Windows\Fonts\segoeuib.ttf","SUCCESS",""
"5:54:48.3640382 AM","MediaOffice.exe","7476","CloseFile","C:\Windows\Fonts\segoeuii.ttf","SUCCESS",""
"5:54:48.3640635 AM","MediaOffice.exe","7476","CloseFile","C:\Windows\Fonts\segoeuiz.ttf","SUCCESS",""
"5:54:48.3645094 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
"5:54:48.3645566 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
"5:54:48.3645860 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
"5:54:48.3646129 AM","MediaOffice.exe","7476","QueryOpen","T:\TestSheet.xls","NAME NOT FOUND",""
 

These entries continue for many hundreds of rows. I am not accustomed to investigating at this level, so not sure how to interpret this.

Share this post


Link to post

And obviously going blind. Thank you! But that's really odd, as the content of my filename variable has not changed.

  • Like 1

Share this post


Link to post
19 minutes ago, David Heffernan said:

Does ExportGridToXLSX convert XLS extension in filename to XLSX?

Yes. The extension was incorrect at the call, and they silently correct it. I'd have preferred an error message.

Share this post


Link to post
4 minutes ago, Attila Kovacs said:

@Bill Meyer are you using explorer? known extensions are hidden?

One of the first things I override. 😉

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×