Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OFN_FILEMUSTEXIST is a lie?

200 views
Skip to first unread message

Karl E. Peterson

unread,
Dec 5, 2007, 3:25:39 PM12/5/07
to
Hi Folks --

Playing around with using the GetOpenFileName API, and it seems that the
OFN_FILEMUSTEXIST (with or without OFN_PATHMUSTEXIST) doesn't always work as
expected. It works fine (msgbox slap delivered) if you type in a filename that
doesn't exist. But, if you select a file in one folder, then navigate to a
different folder and press OK, the result is a combination of the old file and new
folder - almost always a nonexistant beast.

In fact, you can easily demonstrate this difference by using Notepad. Compare the
warnings you get in these two cases:

File - Open - [type nonsense filename] - OK

and,

File - Open - [select file] - [navigate to different drive or folder] - OK

Makes ya kinda go, "Hmmmmmm...", huh? Anyone ever seen this before? FileExists
test always required, no matter what?

Thanks... Karl
--
.NET: It's About Trust!
http://vfred.mvps.org


Ken Halter

unread,
Dec 5, 2007, 3:40:56 PM12/5/07
to
"Karl E. Peterson" <ka...@mvps.org> wrote in message
news:%23FHzA03...@TK2MSFTNGP06.phx.gbl...

fwiw, I can repro the problem with the common dialog.

Seems that.... if you select a file and use the CDL's up arrow to get to
parent folders, or the dropdown to select an entirely different
drive/folder, it ignores the flags, but if you select a file and browse to
another folder by selecting something in the dialogs listview, it complains,
as it should.

So... geezzz... looks like the only way it works is by selecting something
from the dialogs listview window.

Here's the "rocket science" code I used for the tests <g>
'========
Private Sub Command1_Click()
On Error GoTo ErrorTrap

With CommonDialog1
.CancelError = True
.Flags = cdlOFNFileMustExist Or cdlOFNPathMustExist
.ShowOpen
Debug.Print .FileName
End With

Terminate:
Exit Sub
ErrorTrap:
Debug.Print Err.Number
Resume Terminate
End Sub
'========

I wonder how long that "feature" has been with us <g> At least, no one can
say "it's VBs fault"

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm


Bob Butler

unread,
Dec 5, 2007, 3:58:48 PM12/5/07
to
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:uep3H$3NIHA...@TK2MSFTNGP04.phx.gbl...

Same here under Win2K & XP. It seems to be fixed in Vista.

Karl E. Peterson

unread,
Dec 5, 2007, 3:59:42 PM12/5/07
to
Ken Halter wrote:
> fwiw, I can repro the problem with the common dialog.

Cool. I wanted to try that, just as a sanity check, but I always hated adding it to
a project and just didn't get around to it. <g>

> So... geezzz... looks like the only way it works is by selecting something
> from the dialogs listview window.

Yep.

> I wonder how long that "feature" has been with us <g> At least, no one can
> say "it's VBs fault"

So far, I've seen it in 2000 and XP. I've *not* been able to repro it on Windows
95, though! So it definitely crept in somewhere along the 32-bit line.

Larry Serflaten

unread,
Dec 5, 2007, 4:02:38 PM12/5/07
to

"Karl E. Peterson" <ka...@mvps.org> wrote

> In fact, you can easily demonstrate this difference by using Notepad. Compare the


> warnings you get in these two cases:
>
> File - Open - [type nonsense filename] - OK
>
> and,
>
> File - Open - [select file] - [navigate to different drive or folder] - OK


I get a 'File Not Found' error for both cases which would be the expected
result.... ???

The only difference was that in the latter case, the full path was shown
ahead of the filename.

LFS


Karl E. Peterson

unread,
Dec 5, 2007, 4:06:04 PM12/5/07
to
Bob Butler wrote:
>> So... geezzz... looks like the only way it works is by selecting something
>> from the dialogs listview window.
>
> Same here under Win2K & XP. It seems to be fixed in Vista.

No kidding? I haven't tried Vista yet. So far, then,

Buggy: 2000, XP
Fixed: Vista, 98, 95

(Yeah, I just tried 98, as well. Anyone have an NT4 VM?)

Karl E. Peterson

unread,
Dec 5, 2007, 4:07:12 PM12/5/07
to

What OS? (So far, the bug has only been seen in 2000 and XP.)

Karl E. Peterson

unread,
Dec 5, 2007, 8:28:37 PM12/5/07
to
Ken Halter wrote:
> Seems that.... if you select a file and use the CDL's up arrow to get to
> parent folders, or the dropdown to select an entirely different
> drive/folder, it ignores the flags, but if you select a file and browse to
> another folder by selecting something in the dialogs listview, it complains,
> as it should.
>
> So... geezzz... looks like the only way it works is by selecting something
> from the dialogs listview window.

I been a-fiddlin', and it appears there is another way. If you set a hook
(OFN_ENABLEHOOK) on the dialog, and watch for the CDN_FILEOK notification, you get a
chance to reject the user's input at that point. It's kinda messy, though, if you
OFN_ALLOWMULTISELECT too -- do you reject if a single file is non-existant, or only
if they all are? Questions, questions...

Bob Butler

unread,
Dec 5, 2007, 8:34:35 PM12/5/07
to
"Karl E. Peterson" <ka...@mvps.org> wrote in message
news:uNiiTd6N...@TK2MSFTNGP05.phx.gbl...

Guess I'm lucky that I always treated the flags as "advisory" and checked
the return as needed anyway. I suspect most people did that, intentioanlly
or not, which is why this hasn't come up as often as it sounds like it
should have.

Larry Serflaten

unread,
Dec 5, 2007, 8:54:04 PM12/5/07
to

"Karl E. Peterson" <ka...@mvps.org> wrote
> >> In fact, you can easily demonstrate this difference by using Notepad. Compare
> >> the warnings you get in these two cases:

> > I get a 'File Not Found' error for both cases which would be the expected


> > result.... ???
> > The only difference was that in the latter case, the full path was shown
> > ahead of the filename.
>
> What OS? (So far, the bug has only been seen in 2000 and XP.)

Win2000 SP4.

The full path listed in the error message is sporactic, there may be a
pattern to it, but it certainly is not consistant. For example, after selecting
the 'All Files' option and then typing in a non-existant name, the error message
shows just the name with the extension ".txt" added. When I dismiss that
error and immediately hit Enter again (expecting the same error) the full
path shows, without the added extension. If I add one character to the name,
and hit Enter the .txt extension is back, without the path. Pressing Enter again
shows the full path, with no extension....

So, it would seem changing directories is a red herring, I am thinking the
editing (or changing) of the "File name" textbox is the culprit....

LFS


Karl E. Peterson

unread,
Dec 5, 2007, 8:58:49 PM12/5/07
to
Bob Butler wrote:
> "Karl E. Peterson" <ka...@mvps.org> wrote ...

The really nice thing about it working as it should is that the Open dialog never
gets dismissed. The user can just reselect or cancel. The dismissal of the Open
dialog, followed by an application error message, is just downright rude in
comparison.

More likely, why no one's complained -- how many folks select a file and *then*
change folders before pressing OK?

Karl E. Peterson

unread,
Dec 5, 2007, 9:00:26 PM12/5/07
to

I think you're uncovering another bug. <g> That definitely doesn't sound like the
same one.

Larry Serflaten

unread,
Dec 5, 2007, 9:18:35 PM12/5/07
to

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote

> fwiw, I can repro the problem with the common dialog.

Ditto....

LFS


Kevin Provance

unread,
Dec 5, 2007, 9:36:33 PM12/5/07
to
| More likely, why no one's complained -- how many folks select a file and
*then*
| change folders before pressing OK?

::sheepishly raise hand::

Me?

:-)


Karl E. Peterson

unread,
Dec 5, 2007, 9:52:51 PM12/5/07
to

Well hell, I obviously did it as well, or I wouldn't have found it! <g>

Just had it pointed out to me, elsewhere, that *how* you change folders also has a
bearing on whether the bug presents itself. The UpFolder button is the chief
culprit.

Walter Wang [MSFT]

unread,
Dec 5, 2007, 10:57:27 PM12/5/07
to
Hi Karl,

Would you please check the version number of
%windir%\system32\comdlg32.dll? I checked mine which has version
6.0.2900.2180 on Windows XP and it doesn't have the issue you mentioned.

Regards,
Walter Wang (waw...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Ken Halter

unread,
Dec 5, 2007, 11:13:20 PM12/5/07
to
""Walter Wang [MSFT]"" <waw...@online.microsoft.com> wrote in message
news:IOyHhw7N...@TK2MSFTNGHUB02.phx.gbl...

> Hi Karl,
>
> Would you please check the version number of
> %windir%\system32\comdlg32.dll? I checked mine which has version
> 6.0.2900.2180 on Windows XP and it doesn't have the issue you mentioned.

Same version I'm running... using VBs common dialog control (v6.1.97.82), I
can reproduce the problem.

Steve Gerrard

unread,
Dec 6, 2007, 12:34:41 AM12/6/07
to

""Walter Wang [MSFT]"" <waw...@online.microsoft.com> wrote in message
news:IOyHhw7N...@TK2MSFTNGHUB02.phx.gbl...
> Hi Karl,
>
> Would you please check the version number of
> %windir%\system32\comdlg32.dll? I checked mine which has version
> 6.0.2900.2180 on Windows XP and it doesn't have the issue you mentioned.
>
> Regards,
> Walter Wang (waw...@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>

Does Notepad use that? Karl pointed out that the same thing happens in Notepad.
Pick a file to open, then change directories using the "UpFolder" button, then
click okay. Dialog closes, then a message pops up.

My machine has 6.0.2900.2180 as well.

Karl E. Peterson

unread,
Dec 6, 2007, 1:10:56 PM12/6/07
to
Hi Walter --

> Would you please check the version number of
> %windir%\system32\comdlg32.dll? I checked mine which has version
> 6.0.2900.2180 on Windows XP and it doesn't have the issue you mentioned.

Yep, this system has 6.0.2900.2180, and is running XP/SP2.

I've found that the problem is most easily seen using the UpFolder button *after*
selecting a file. If you navigate to another folder using, say, the Places bar the
OFN_FILEMUSTEXIST trap is triggered as would be expected.

Walter Wang [MSFT]

unread,
Dec 9, 2007, 11:56:35 PM12/9/07
to
Hi Karl,

Thanks for your update.

Yes I have been confirmed by product group that this is a known issue and
has been fixed in Vista.

Please contact our Customer Support and Service for more information. Since
it's a confirmed issue of our products, the support incident will be free.

Larry Serflaten

unread,
Dec 10, 2007, 8:00:37 AM12/10/07
to

""Walter Wang [MSFT]"" <waw...@online.microsoft.com> wrote

> Yes I have been confirmed by product group that this is a known issue and


> has been fixed in Vista.

What are the specifics? Is there a Knowlege Base article somewhere?

LFS


Karl E. Peterson

unread,
Dec 10, 2007, 12:18:35 PM12/10/07
to
Hi Walter --

> Yes I have been confirmed by product group that this is a known issue and
> has been fixed in Vista.

How about the upcoming XP-SP3? That's where it really needs to be addressed, since
that's the OS folks are using.

> Please contact our Customer Support and Service for more information. Since
> it's a confirmed issue of our products, the support incident will be free.

Shouldn't it be online, somewhere? Is there a KB article? Or are folks going to
have to use Google Groups, to search developer newsgroups, to find this little
conversation in order to understand what's happening here?

David Youngblood

unread,
Dec 10, 2007, 1:18:11 PM12/10/07
to
""Walter Wang [MSFT]"" <waw...@online.microsoft.com> wrote in message
news:FuUsPkuO...@TK2MSFTNGHUB02.phx.gbl...

> Hi Karl,
>
> Thanks for your update.
>
> Yes I have been confirmed by product group that this is a known issue and
> has been fixed in Vista.
>
> Please contact our Customer Support and Service for more information. Since
> it's a confirmed issue of our products, the support incident will be free.
>
> Regards,
> Walter Wang (waw...@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support

On a semi-related topic, has there been any action on this bug,
"Common dialog control returns wrong filename" (ShowOpen)

http://groups.google.com/group/microsoft.public.vb.bugs/browse_frm/thread/a322782f10ca7043/78025c3c351ec17b?lnk=st&q=#78025c3c351ec17b

David


Walter Wang [MSFT]

unread,
Dec 11, 2007, 10:08:54 PM12/11/07
to
Hi all,

To summarize:

* I have contacted shell team and this has been fixed in Vista (the common
dialog is rewritten and doesn't have this issue); we currently don't have a
hotfix on Windows XP, therefore I've filed a report for this issue and
product group will work on the fix. It's currently not determined yet if it
will be released as a standalone hotfix or included in future service pack.
* I will file a request to create a public KB for this known issue on
Windows XP. Again, I cannot guarantee when it will be publicly available.

We're sorry for the inconvenience caused and thanks for your feedback.

Karl E. Peterson

unread,
Dec 12, 2007, 1:30:37 PM12/12/07
to
I appreciate your efforts, both with the responsible parties and here in the group,
Walter. I know there's little you can do but let them know.

Thanks... Karl
--
.NET: It's About Trust!
http://vfred.mvps.org

MikeD

unread,
Dec 12, 2007, 8:42:07 PM12/12/07
to

""Walter Wang [MSFT]"" <waw...@online.microsoft.com> wrote in message
news:5TjGbxGP...@TK2MSFTNGHUB02.phx.gbl...

> Hi all,
>
> To summarize:
>
> * I have contacted shell team and this has been fixed in Vista (the common
> dialog is rewritten and doesn't have this issue); we currently don't have
> a
> hotfix on Windows XP, therefore I've filed a report for this issue and
> product group will work on the fix. It's currently not determined yet if
> it
> will be released as a standalone hotfix or included in future service
> pack.
> * I will file a request to create a public KB for this known issue on
> Windows XP. Again, I cannot guarantee when it will be publicly available.
>

Sounds like you've done as much as you can, Walter. That's as much as we can
ask, and your efforts are appreciated.

Thanks for the feedback.

--
Mike
Microsoft MVP Visual Basic


0 new messages