473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Curious SaveFileDialog gotcha

I've just determined, by experimenting, that regardless of its Filter and
DefaultExt properties, a SaveFileDialog will let you save the file with
*any* registered extension.

For instance, if you specify a SaveFileDialog with the attributes:

AddExtension = true
Filter = "Foo files|*.foo"
DefaultExt = "foo"

and you type the file name qwerty, you get qwerty.foo, exactly as you might
expect.

And if you type qwerty.bla (where .bla is not a registered extension), you
get qwerty.bla.foo. Again so far so good.

But if you type the file name qwerty.exe, or qwerty.bat, or qwerty.doc, or
any other file name with a registered extension, then .foo is *not* appended
to it.

This does not strike me as entirely wise, and I haven't found any
documentation of it!

Is there another attribute that will disable it (so my file dialog will
really insist on file names ending in .foo)?

Thanks!

Michael A. Covington - Artificial Intelligence Ctr - University of Georgia

"In the core C# language it is simply not possible to have an uninitialized
variable, a 'dangling' pointer, or an expression that indexes an array
beyond its bounds. Whole categories of bugs that routinely plague C and C++
programs are thus eliminated." - A. Hejlsberg, The C# Programming Language
Nov 15 '05 #1
4 3433
IIRC this has been true ever since long filenames were introduced in Win
'95.

Having said that, I disagree, this DOES make sense. I'm not sure I can
coherently explain why, I'll have to think on that one.

Filter only populates the filetypes dropdown and provides a way to display
certain filetypes, it has nothing to do with the extension used when
creating the file name.

You may be able to change this behavior by inheriting your own class from
SaveFileDialog and overriding OnFileOk, but it may not be worth the trouble.

Regards
Brian W
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> wrote
in message news:%2****************@tk2msftngp13.phx.gbl...
I've just determined, by experimenting, that regardless of its Filter and
DefaultExt properties, a SaveFileDialog will let you save the file with
*any* registered extension.

For instance, if you specify a SaveFileDialog with the attributes:

AddExtension = true
Filter = "Foo files|*.foo"
DefaultExt = "foo"

and you type the file name qwerty, you get qwerty.foo, exactly as you might expect.

And if you type qwerty.bla (where .bla is not a registered extension), you
get qwerty.bla.foo. Again so far so good.

But if you type the file name qwerty.exe, or qwerty.bat, or qwerty.doc, or
any other file name with a registered extension, then .foo is *not* appended to it.

This does not strike me as entirely wise, and I haven't found any
documentation of it!

Is there another attribute that will disable it (so my file dialog will
really insist on file names ending in .foo)?

Thanks!

Michael A. Covington - Artificial Intelligence Ctr - University of Georgia

"In the core C# language it is simply not possible to have an uninitialized variable, a 'dangling' pointer, or an expression that indexes an array
beyond its bounds. Whole categories of bugs that routinely plague C and C++ programs are thus eliminated." - A. Hejlsberg, The C# Programming Language

Nov 15 '05 #2

"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
IIRC this has been true ever since long filenames were introduced in Win
'95.

Having said that, I disagree, this DOES make sense. I'm not sure I can
coherently explain why, I'll have to think on that one.

Filter only populates the filetypes dropdown and provides a way to display
certain filetypes, it has nothing to do with the extension used when
creating the file name.

You may be able to change this behavior by inheriting your own class from
SaveFileDialog and overriding OnFileOk, but it may not be worth the

trouble.

But what surprised me is that it apparently looks into the registry to
decide what is and is not an extension.

If it had accepted any extension typed by the user, and only added one when
there was one, I would have understood it.
Nov 15 '05 #3
Here's a simple brute force way to accomplish this (VB.Net code - if that matters)

sFilePath = objSaveFileDialog.FileNam

If Not sFilePath.EndsWith(".foo") The
sFilePath &= ".foo
End I

HTH
Kevin
Nov 15 '05 #4
That's what I wound up doing!

"Kevin" <an*******@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
Here's a simple brute force way to accomplish this (VB.Net code - if that matters):
sFilePath = objSaveFileDialog.FileName

If Not sFilePath.EndsWith(".foo") Then
sFilePath &= ".foo"
End If

HTH,
Kevin

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ken Allen | last post by:
I have enocuntered something wierd. If I invoke an instance of the above dialog and elect to save the file in a directory where a file of that name does not exist, then the return is...
2
by: Yoshi | last post by:
Hi Everyone! I am using the SaveFileDialog class. I want the user to specify the "SaveAs" filename so I can use that name when creating a text document. Here is my question below. When the...
2
by: Dennis C. Drumm | last post by:
Is there a way for the parent that calls the SaveFileDialog.ShowDialog to consume events associated with this dialog such as LocationChanged, Moved and Closed events? I had been working on a way...
5
by: juli | last post by:
Hello dear fellows! Is there any chance that you know how can I upload a file with the saveFileDialog control to a specific folder-> I want any file uploaded to be save on specific folder with...
3
by: josh | last post by:
How do I make it actually save or open a file? It only opens the dialogs. What do I type to get it to save? Here's what I have so far: Public Class frmMainApp Inherits...
2
by: ad | last post by:
Hi, I want to use saveFileDialog to save a file (like c:\aa.zip) to another place. How can I assgin c:\aa.zip to saveFileDialog
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
3
by: =?Utf-8?B?UmljaA==?= | last post by:
I want to create a class library project (dll) for use with a com app. The idea is to use .Net objects in com. I also want to include a SaveFileDialog in the class library. Is it possible to...
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.