This is a multi-part message in MIME format.

------=_NextPart_000_0071_01C4C67A.66A29FA0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

Hi,

I am using System.Windows.Forms.SaveFileDialog to prompt the user to =
select a file to which data is exported.

I would like the control to always add the default extension, in this =
case .xls, to whatever filename the user enters - but the default =
behavior is that the extension is only added if the user has not already =
entered an extension.
E.g. if the user types in the filename "export.txt" then the =
SaveFileDialog should append .xls to form "export.txt.xls".

Of course I could just do this manually after the user has OK'd but then =
the dialog's prompt for create and overwrite won't be correct.

How can I configure SaveFileDialog to ALWAYS append .xls?

Below is a code snippet that I use to prompt the user for a filename:

public static string GetExportFilename()

{

System.Windows.Forms.SaveFileDialog saveFileDialog =3D new =
SaveFileDialog();

saveFileDialog.DefaultExt =3D =
"*.xls";

saveFileDialog.Filter =3D "Excel =
8.0+ (*.xls)|*.xls";

saveFileDialog.AddExtension =3D =
true;

saveFileDialog.CheckPathExists =3D =
true;

saveFileDialog.CheckFileExists =3D =
false;

saveFileDialog.CreatePrompt =3D =
true;

saveFileDialog.OverwritePrompt =3D =
true; =20

string exportFilename =3D "";

if (saveFileDialog.ShowDialog() =
=3D=3D DialogResult.OK)

{

exportFilename =3D =
saveFileDialog.FileName; =
=20

=20

}

=20

return exportFilename;

}


Regards
Joubert
------=_NextPart_000_0071_01C4C67A.66A29FA0
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DVerdana size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>I am using =
System.Windows.Forms.SaveFileDialog to=20
prompt the user to select a file to which data is exported.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>I would like the control to always =
add the=20
default extension, in this case .xls, to whatever filename the user=20
enters&nbsp;- but the default behavior is that the extension is only =
added if=20
the user has not already entered an extension.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>E.g. if the user types in the =
filename=20
"export.txt" then the&nbsp;SaveFileDialog should append .xls to form=20
"export.txt.xls".</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Of course I could just do this =
manually after the=20
user has OK'd but then the dialog's prompt for create and overwrite =
won't be=20
correct.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>How can I configure SaveFileDialog to =
ALWAYS=20
append .xls?</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Below is a code snippet that I use to =
prompt the=20
user for a filename:</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT face=3DVerdana size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: =
Verdana">public</SPAN><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"> <SPAN=20
style=3D"COLOR: blue">static</SPAN> <SPAN style=3D"COLOR: =
blue">string</SPAN>=20
GetExportFilename()<?xml:namespace prefix =3D o ns =3D=20
"urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt 108pt; mso-layout-grid-align: none"><SPAN =

style=3D"FONT-SIZE: 9pt; FONT-FAMILY: =
Verdana">System.Windows.Forms.SaveFileDialog=20
saveFileDialog =3D <SPAN style=3D"COLOR: blue">new</SPAN>=20
SaveFileDialog();<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.DefaultExt =3D <SPAN=20
style=3D"COLOR: navy">"*.xls"</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.Filter =3D <SPAN style=3D"COLOR: navy">"Excel =
8.0+=20
(*.xls)|*.xls"</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.AddExtension =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CheckPathExists =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CheckFileExists =3D <SPAN=20
style=3D"COLOR: blue">false</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CreatePrompt =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.OverwritePrompt =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">string</SPAN> exportFilename =3D =
<SPAN=20
style=3D"COLOR: navy">""</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">if</SPAN> =
(saveFileDialog.ShowDialog() =3D=3D=20
DialogResult.OK)<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>exportFilename =3D saveFileDialog.FileName;<SPAN=20
style=3D"mso-tab-count: =
5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: =
Verdana"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">return</SPAN>=20
exportFilename;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}</SPAN></P></FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Regards</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>Joubert</FONT></DIV></BODY></HTML>

------=_NextPart_000_0071_01C4C67A.66A29FA0--

Re: FileSaveDialog and default file extension by ShaneB

ShaneB
Tue Nov 09 16:33:37 CST 2004

If you want this done, you'll have to do it yourself. Be warned, this is a
non-standard behavior that you're trying to implement and is not a good idea
IMHO.

ShaneB



Re: FileSaveDialog and default file extension by Bernie

Bernie
Tue Nov 09 21:38:29 CST 2004

This is a multi-part message in MIME format.

------=_NextPart_000_0044_01C4C6AC.D5F31A10
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

Hi Joubert,

It's funny that you ask this - I was just developing a system where my =
user saves .sql files for later loading and editing - I thought about =
the same thing!

I decided against forcing the .sql extension, but when I considered it, =
I thought I would simply look for a . in the filename; if it were =
present, I would determine if it was followed by only 'sql'; if not, I =
would append the .sql to the end of the filename.

HTH,

Bernie Yaeger

"msnews.microsoft.com" <j@j> wrote in message =
news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
Hi,

I am using System.Windows.Forms.SaveFileDialog to prompt the user to =
select a file to which data is exported.

I would like the control to always add the default extension, in this =
case .xls, to whatever filename the user enters - but the default =
behavior is that the extension is only added if the user has not already =
entered an extension.
E.g. if the user types in the filename "export.txt" then the =
SaveFileDialog should append .xls to form "export.txt.xls".

Of course I could just do this manually after the user has OK'd but =
then the dialog's prompt for create and overwrite won't be correct.

How can I configure SaveFileDialog to ALWAYS append .xls?

Below is a code snippet that I use to prompt the user for a filename:

public static string GetExportFilename()

{

System.Windows.Forms.SaveFileDialog saveFileDialog =3D new =
SaveFileDialog();

saveFileDialog.DefaultExt =3D =
"*.xls";

saveFileDialog.Filter =3D "Excel =
8.0+ (*.xls)|*.xls";

saveFileDialog.AddExtension =3D =
true;

saveFileDialog.CheckPathExists =
=3D true;

saveFileDialog.CheckFileExists =
=3D false;

saveFileDialog.CreatePrompt =3D =
true;

saveFileDialog.OverwritePrompt =
=3D true; =20

string exportFilename =3D "";

if (saveFileDialog.ShowDialog() =
=3D=3D DialogResult.OK)

{

exportFilename =3D =
saveFileDialog.FileName; =
=20

=20

}

=20

return exportFilename;

}


Regards
Joubert
------=_NextPart_000_0044_01C4C6AC.D5F31A10
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o =3D "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi Joubert,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>It's funny that you ask this - I was =
just=20
developing a system where my user saves .sql files for later loading and =
editing=20
- I thought about the same thing!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I decided against forcing the .sql =
extension, but=20
when I considered it, I thought I would simply look for a . in the =
filename; if=20
it were present, I would determine if it was followed by only 'sql'; if =
not, I=20
would append the .sql to the end of the filename.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>HTH,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Bernie Yaeger</FONT></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"msnews.microsoft.com" &lt;<A href=3D"mailto:j@j">j@j</A>&gt; =
wrote in=20
message <A=20
=
href=3D"news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl">news:eYUIEnmxEHA.4044=
@tk2msftngp13.phx.gbl</A>...</DIV>
<DIV><FONT face=3DVerdana size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>I am using =
System.Windows.Forms.SaveFileDialog=20
to prompt the user to select a file to which data is =
exported.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>I would like the control to always =
add the=20
default extension, in this case .xls, to whatever filename the user=20
enters&nbsp;- but the default behavior is that the extension is only =
added if=20
the user has not already entered an extension.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>E.g. if the user types in the =
filename=20
"export.txt" then the&nbsp;SaveFileDialog should append .xls to form=20
"export.txt.xls".</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Of course I could just do this =
manually after=20
the user has OK'd but then the dialog's prompt for create and =
overwrite won't=20
be correct.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>How can I configure SaveFileDialog =
to ALWAYS=20
append .xls?</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Below is a code snippet that I use =
to prompt=20
the user for a filename:</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT face=3DVerdana size=3D2>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: =
Verdana">public</SPAN><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"> <SPAN=20
style=3D"COLOR: blue">static</SPAN> <SPAN style=3D"COLOR: =
blue">string</SPAN>=20
GetExportFilename()<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt 108pt; mso-layout-grid-align: =
none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: =
Verdana">System.Windows.Forms.SaveFileDialog=20
saveFileDialog =3D <SPAN style=3D"COLOR: blue">new</SPAN>=20
SaveFileDialog();<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.DefaultExt =3D <SPAN=20
style=3D"COLOR: navy">"*.xls"</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.Filter =3D <SPAN style=3D"COLOR: navy">"Excel =
8.0+=20
(*.xls)|*.xls"</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.AddExtension =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CheckPathExists =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CheckFileExists =3D <SPAN=20
style=3D"COLOR: blue">false</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.CreatePrompt =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>saveFileDialog.OverwritePrompt =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">string</SPAN> exportFilename =3D =
<SPAN=20
style=3D"COLOR: navy">""</SPAN>;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">if</SPAN> =
(saveFileDialog.ShowDialog() =3D=3D=20
DialogResult.OK)<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>{<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>exportFilename =3D saveFileDialog.FileName;<SPAN=20
style=3D"mso-tab-count: =
5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}<o:p></o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: =
Verdana"><o:p>&nbsp;</o:p></SPAN></P>
<P class=3DMsoNormal=20
style=3D"MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN><SPAN style=3D"COLOR: blue">return</SPAN>=20
exportFilename;<o:p></o:p></SPAN></P>
<P class=3DMsoNormal style=3D"MARGIN: 0cm 0cm 0pt"><SPAN=20
style=3D"FONT-SIZE: 9pt; FONT-FAMILY: Verdana"><SPAN=20
style=3D"mso-tab-count: =
2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</SPAN>}</SPAN></P></FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Regards</FONT></DIV>
<DIV><FONT face=3DVerdana =
size=3D2>Joubert</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0044_01C4C6AC.D5F31A10--


Re: FileSaveDialog and default file extension by Joubert

Joubert
Wed Nov 10 06:49:10 CST 2004

Hi Bernie,

I've also done this but then when the file already exists, the
SaveFileDialog does not prompt the user to overwrite. And if the file does
not exist, the SFDialog does not prompt the user to create.

Have a look at Excel (I'm using 2003) - add an extension to a file in the
Save dialog - the Save File Dialog then adds the .xls extension (not the
calling code).
This is what I'm trying to achieve....

"Bernie Yaeger" wrote:

> Hi Joubert,
>
> It's funny that you ask this - I was just developing a system where my user saves .sql files for later loading and editing - I thought about the same thing!
>
> I decided against forcing the .sql extension, but when I considered it, I thought I would simply look for a . in the filename; if it were present, I would determine if it was followed by only 'sql'; if not, I would append the .sql to the end of the filename.
>
> HTH,
>
> Bernie Yaeger
>
> "msnews.microsoft.com" <j@j> wrote in message news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
> Hi,
>
> I am using System.Windows.Forms.SaveFileDialog to prompt the user to select a file to which data is exported.
>
> I would like the control to always add the default extension, in this case .xls, to whatever filename the user enters - but the default behavior is that the extension is only added if the user has not already entered an extension.
> E.g. if the user types in the filename "export.txt" then the SaveFileDialog should append .xls to form "export.txt.xls".
>
> Of course I could just do this manually after the user has OK'd but then the dialog's prompt for create and overwrite won't be correct.
>
> How can I configure SaveFileDialog to ALWAYS append .xls?
>
> Below is a code snippet that I use to prompt the user for a filename:
>
> public static string GetExportFilename()
>
> {
>
> System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
>
> saveFileDialog.DefaultExt = "*.xls";
>
> saveFileDialog.Filter = "Excel 8.0+ (*.xls)|*.xls";
>
> saveFileDialog.AddExtension = true;
>
> saveFileDialog.CheckPathExists = true;
>
> saveFileDialog.CheckFileExists = false;
>
> saveFileDialog.CreatePrompt = true;
>
> saveFileDialog.OverwritePrompt = true;
>
> string exportFilename = "";
>
> if (saveFileDialog.ShowDialog() == DialogResult.OK)
>
> {
>
> exportFilename = saveFileDialog.FileName;
>
>
>
> }
>
>
>
> return exportFilename;
>
> }
>
>
> Regards
> Joubert

Re: FileSaveDialog and default file extension by Joubert

Joubert
Wed Nov 10 06:50:03 CST 2004

Hi Shane,

Have a look at Excel (I'm using 2003) - add an extension to a file in the
Save dialog - the Save File Dialog then adds the .xls extension (not the
calling code).
This is what I'm trying to achieve....

"ShaneB" wrote:

> If you want this done, you'll have to do it yourself. Be warned, this is a
> non-standard behavior that you're trying to implement and is not a good idea
> IMHO.
>
> ShaneB
>
>
>

Re: FileSaveDialog and default file extension by Bernie

Bernie
Wed Nov 10 09:30:29 CST 2004

Hi Joubert,

Yes, I see what you mean. Unfortunately, the savefiledialog, all of the
replacement common dialogs, are 'black boxes', which don't allow us to do
too much with it. I will try working with the dispose event to see if I can
trap it there, searching first for a 'file exists' etc.

I'll let you know what I discover; please let me know if you find a
solution.

Bernie

"Joubert" <Joubert@discussions.microsoft.com> wrote in message
news:4169EAD3-A285-4730-B9CC-DA22E7EC77B2@microsoft.com...
> Hi Bernie,
>
> I've also done this but then when the file already exists, the
> SaveFileDialog does not prompt the user to overwrite. And if the file does
> not exist, the SFDialog does not prompt the user to create.
>
> Have a look at Excel (I'm using 2003) - add an extension to a file in the
> Save dialog - the Save File Dialog then adds the .xls extension (not the
> calling code).
> This is what I'm trying to achieve....
>
> "Bernie Yaeger" wrote:
>
>> Hi Joubert,
>>
>> It's funny that you ask this - I was just developing a system where my
>> user saves .sql files for later loading and editing - I thought about the
>> same thing!
>>
>> I decided against forcing the .sql extension, but when I considered it, I
>> thought I would simply look for a . in the filename; if it were present,
>> I would determine if it was followed by only 'sql'; if not, I would
>> append the .sql to the end of the filename.
>>
>> HTH,
>>
>> Bernie Yaeger
>>
>> "msnews.microsoft.com" <j@j> wrote in message
>> news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
>> Hi,
>>
>> I am using System.Windows.Forms.SaveFileDialog to prompt the user to
>> select a file to which data is exported.
>>
>> I would like the control to always add the default extension, in this
>> case .xls, to whatever filename the user enters - but the default
>> behavior is that the extension is only added if the user has not already
>> entered an extension.
>> E.g. if the user types in the filename "export.txt" then the
>> SaveFileDialog should append .xls to form "export.txt.xls".
>>
>> Of course I could just do this manually after the user has OK'd but
>> then the dialog's prompt for create and overwrite won't be correct.
>>
>> How can I configure SaveFileDialog to ALWAYS append .xls?
>>
>> Below is a code snippet that I use to prompt the user for a filename:
>>
>> public static string GetExportFilename()
>>
>> {
>>
>> System.Windows.Forms.SaveFileDialog saveFileDialog = new
>> SaveFileDialog();
>>
>> saveFileDialog.DefaultExt =
>> "*.xls";
>>
>> saveFileDialog.Filter = "Excel
>> 8.0+ (*.xls)|*.xls";
>>
>> saveFileDialog.AddExtension =
>> true;
>>
>> saveFileDialog.CheckPathExists =
>> true;
>>
>> saveFileDialog.CheckFileExists =
>> false;
>>
>> saveFileDialog.CreatePrompt =
>> true;
>>
>> saveFileDialog.OverwritePrompt =
>> true;
>>
>> string exportFilename = "";
>>
>> if (saveFileDialog.ShowDialog()
>> == DialogResult.OK)
>>
>> {
>>
>> exportFilename =
>> saveFileDialog.FileName;
>>
>>
>>
>> }
>>
>>
>>
>> return exportFilename;
>>
>> }
>>
>>
>> Regards
>> Joubert



Re: FileSaveDialog and default file extension by Joubert

Joubert
Wed Nov 10 15:14:21 CST 2004

Hi Bernie,

Deal - I will also research a bit more and let you know what I find.

Cheers
Joubert


"Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
news:uC351ozxEHA.4004@tk2msftngp13.phx.gbl...
> Hi Joubert,
>
> Yes, I see what you mean. Unfortunately, the savefiledialog, all of the
> replacement common dialogs, are 'black boxes', which don't allow us to do
> too much with it. I will try working with the dispose event to see if I
> can trap it there, searching first for a 'file exists' etc.
>
> I'll let you know what I discover; please let me know if you find a
> solution.
>
> Bernie
>
> "Joubert" <Joubert@discussions.microsoft.com> wrote in message
> news:4169EAD3-A285-4730-B9CC-DA22E7EC77B2@microsoft.com...
>> Hi Bernie,
>>
>> I've also done this but then when the file already exists, the
>> SaveFileDialog does not prompt the user to overwrite. And if the file
>> does
>> not exist, the SFDialog does not prompt the user to create.
>>
>> Have a look at Excel (I'm using 2003) - add an extension to a file in the
>> Save dialog - the Save File Dialog then adds the .xls extension (not the
>> calling code).
>> This is what I'm trying to achieve....
>>
>> "Bernie Yaeger" wrote:
>>
>>> Hi Joubert,
>>>
>>> It's funny that you ask this - I was just developing a system where my
>>> user saves .sql files for later loading and editing - I thought about
>>> the same thing!
>>>
>>> I decided against forcing the .sql extension, but when I considered it,
>>> I thought I would simply look for a . in the filename; if it were
>>> present, I would determine if it was followed by only 'sql'; if not, I
>>> would append the .sql to the end of the filename.
>>>
>>> HTH,
>>>
>>> Bernie Yaeger
>>>
>>> "msnews.microsoft.com" <j@j> wrote in message
>>> news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
>>> Hi,
>>>
>>> I am using System.Windows.Forms.SaveFileDialog to prompt the user to
>>> select a file to which data is exported.
>>>
>>> I would like the control to always add the default extension, in this
>>> case .xls, to whatever filename the user enters - but the default
>>> behavior is that the extension is only added if the user has not already
>>> entered an extension.
>>> E.g. if the user types in the filename "export.txt" then the
>>> SaveFileDialog should append .xls to form "export.txt.xls".
>>>
>>> Of course I could just do this manually after the user has OK'd but
>>> then the dialog's prompt for create and overwrite won't be correct.
>>>
>>> How can I configure SaveFileDialog to ALWAYS append .xls?
>>>
>>> Below is a code snippet that I use to prompt the user for a filename:
>>>
>>> public static string GetExportFilename()
>>>
>>> {
>>>
>>> System.Windows.Forms.SaveFileDialog saveFileDialog = new
>>> SaveFileDialog();
>>>
>>> saveFileDialog.DefaultExt =
>>> "*.xls";
>>>
>>> saveFileDialog.Filter = "Excel
>>> 8.0+ (*.xls)|*.xls";
>>>
>>> saveFileDialog.AddExtension =
>>> true;
>>>
>>> saveFileDialog.CheckPathExists =
>>> true;
>>>
>>> saveFileDialog.CheckFileExists =
>>> false;
>>>
>>> saveFileDialog.CreatePrompt =
>>> true;
>>>
>>> saveFileDialog.OverwritePrompt =
>>> true;
>>>
>>> string exportFilename = "";
>>>
>>> if (saveFileDialog.ShowDialog()
>>> == DialogResult.OK)
>>>
>>> {
>>>
>>> exportFilename =
>>> saveFileDialog.FileName;
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>> return exportFilename;
>>>
>>> }
>>>
>>>
>>> Regards
>>> Joubert
>
>



Re: FileSaveDialog and default file extension by ShaneB

ShaneB
Wed Nov 10 18:31:05 CST 2004

My apologies for the error...brainfart. Unfortunately, I believe you're
still stuck coding it yourself.

ShaneB

"Joubert" <Joubert@discussions.microsoft.com> wrote in message
news:7758E38C-2905-4BDB-85F3-FD4DF8B6796A@microsoft.com...
> Hi Shane,
>
> Have a look at Excel (I'm using 2003) - add an extension to a file in the
> Save dialog - the Save File Dialog then adds the .xls extension (not the
> calling code).
> This is what I'm trying to achieve....
>
> "ShaneB" wrote:
>
>> If you want this done, you'll have to do it yourself. Be warned, this is
>> a
>> non-standard behavior that you're trying to implement and is not a good
>> idea
>> IMHO.
>>
>> ShaneB
>>
>>
>>



Re: FileSaveDialog and default file extension by Bernie

Bernie
Thu Nov 11 07:39:16 CST 2004

Hi Joubert,

Sorry to report, but I spent about 2 hours last night trying all kinds of
things and got nowhere. The dispose event was of no help at all.

Hope you have more luck than I did.

Bernie

"Joubert" <j@j> wrote in message
news:%23Wbbhp2xEHA.1524@TK2MSFTNGP09.phx.gbl...
> Hi Bernie,
>
> Deal - I will also research a bit more and let you know what I find.
>
> Cheers
> Joubert
>
>
> "Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
> news:uC351ozxEHA.4004@tk2msftngp13.phx.gbl...
>> Hi Joubert,
>>
>> Yes, I see what you mean. Unfortunately, the savefiledialog, all of the
>> replacement common dialogs, are 'black boxes', which don't allow us to do
>> too much with it. I will try working with the dispose event to see if I
>> can trap it there, searching first for a 'file exists' etc.
>>
>> I'll let you know what I discover; please let me know if you find a
>> solution.
>>
>> Bernie
>>
>> "Joubert" <Joubert@discussions.microsoft.com> wrote in message
>> news:4169EAD3-A285-4730-B9CC-DA22E7EC77B2@microsoft.com...
>>> Hi Bernie,
>>>
>>> I've also done this but then when the file already exists, the
>>> SaveFileDialog does not prompt the user to overwrite. And if the file
>>> does
>>> not exist, the SFDialog does not prompt the user to create.
>>>
>>> Have a look at Excel (I'm using 2003) - add an extension to a file in
>>> the
>>> Save dialog - the Save File Dialog then adds the .xls extension (not the
>>> calling code).
>>> This is what I'm trying to achieve....
>>>
>>> "Bernie Yaeger" wrote:
>>>
>>>> Hi Joubert,
>>>>
>>>> It's funny that you ask this - I was just developing a system where my
>>>> user saves .sql files for later loading and editing - I thought about
>>>> the same thing!
>>>>
>>>> I decided against forcing the .sql extension, but when I considered it,
>>>> I thought I would simply look for a . in the filename; if it were
>>>> present, I would determine if it was followed by only 'sql'; if not, I
>>>> would append the .sql to the end of the filename.
>>>>
>>>> HTH,
>>>>
>>>> Bernie Yaeger
>>>>
>>>> "msnews.microsoft.com" <j@j> wrote in message
>>>> news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
>>>> Hi,
>>>>
>>>> I am using System.Windows.Forms.SaveFileDialog to prompt the user to
>>>> select a file to which data is exported.
>>>>
>>>> I would like the control to always add the default extension, in this
>>>> case .xls, to whatever filename the user enters - but the default
>>>> behavior is that the extension is only added if the user has not
>>>> already entered an extension.
>>>> E.g. if the user types in the filename "export.txt" then the
>>>> SaveFileDialog should append .xls to form "export.txt.xls".
>>>>
>>>> Of course I could just do this manually after the user has OK'd but
>>>> then the dialog's prompt for create and overwrite won't be correct.
>>>>
>>>> How can I configure SaveFileDialog to ALWAYS append .xls?
>>>>
>>>> Below is a code snippet that I use to prompt the user for a filename:
>>>>
>>>> public static string GetExportFilename()
>>>>
>>>> {
>>>>
>>>> System.Windows.Forms.SaveFileDialog saveFileDialog = new
>>>> SaveFileDialog();
>>>>
>>>> saveFileDialog.DefaultExt =
>>>> "*.xls";
>>>>
>>>> saveFileDialog.Filter = "Excel
>>>> 8.0+ (*.xls)|*.xls";
>>>>
>>>> saveFileDialog.AddExtension =
>>>> true;
>>>>
>>>> saveFileDialog.CheckPathExists
>>>> = true;
>>>>
>>>> saveFileDialog.CheckFileExists
>>>> = false;
>>>>
>>>> saveFileDialog.CreatePrompt =
>>>> true;
>>>>
>>>> saveFileDialog.OverwritePrompt
>>>> = true;
>>>>
>>>> string exportFilename = "";
>>>>
>>>> if (saveFileDialog.ShowDialog()
>>>> == DialogResult.OK)
>>>>
>>>> {
>>>>
>>>> exportFilename =
>>>> saveFileDialog.FileName;
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> return exportFilename;
>>>>
>>>> }
>>>>
>>>>
>>>> Regards
>>>> Joubert
>>
>>
>
>



Re: FileSaveDialog and default file extension by Joubert

Joubert
Mon Nov 15 06:22:05 CST 2004

Bernie,

Also no luck here. I am deferring this enhancement to my project till a
later stage.

Cheers
Joubert


"Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
news:%23Nh4WP$xEHA.3400@TK2MSFTNGP10.phx.gbl...
> Hi Joubert,
>
> Sorry to report, but I spent about 2 hours last night trying all kinds of
> things and got nowhere. The dispose event was of no help at all.
>
> Hope you have more luck than I did.
>
> Bernie
>
> "Joubert" <j@j> wrote in message
> news:%23Wbbhp2xEHA.1524@TK2MSFTNGP09.phx.gbl...
>> Hi Bernie,
>>
>> Deal - I will also research a bit more and let you know what I find.
>>
>> Cheers
>> Joubert
>>
>>
>> "Bernie Yaeger" <berniey@cherwellinc.com> wrote in message
>> news:uC351ozxEHA.4004@tk2msftngp13.phx.gbl...
>>> Hi Joubert,
>>>
>>> Yes, I see what you mean. Unfortunately, the savefiledialog, all of the
>>> replacement common dialogs, are 'black boxes', which don't allow us to
>>> do too much with it. I will try working with the dispose event to see
>>> if I can trap it there, searching first for a 'file exists' etc.
>>>
>>> I'll let you know what I discover; please let me know if you find a
>>> solution.
>>>
>>> Bernie
>>>
>>> "Joubert" <Joubert@discussions.microsoft.com> wrote in message
>>> news:4169EAD3-A285-4730-B9CC-DA22E7EC77B2@microsoft.com...
>>>> Hi Bernie,
>>>>
>>>> I've also done this but then when the file already exists, the
>>>> SaveFileDialog does not prompt the user to overwrite. And if the file
>>>> does
>>>> not exist, the SFDialog does not prompt the user to create.
>>>>
>>>> Have a look at Excel (I'm using 2003) - add an extension to a file in
>>>> the
>>>> Save dialog - the Save File Dialog then adds the .xls extension (not
>>>> the
>>>> calling code).
>>>> This is what I'm trying to achieve....
>>>>
>>>> "Bernie Yaeger" wrote:
>>>>
>>>>> Hi Joubert,
>>>>>
>>>>> It's funny that you ask this - I was just developing a system where my
>>>>> user saves .sql files for later loading and editing - I thought about
>>>>> the same thing!
>>>>>
>>>>> I decided against forcing the .sql extension, but when I considered
>>>>> it, I thought I would simply look for a . in the filename; if it were
>>>>> present, I would determine if it was followed by only 'sql'; if not, I
>>>>> would append the .sql to the end of the filename.
>>>>>
>>>>> HTH,
>>>>>
>>>>> Bernie Yaeger
>>>>>
>>>>> "msnews.microsoft.com" <j@j> wrote in message
>>>>> news:eYUIEnmxEHA.4044@tk2msftngp13.phx.gbl...
>>>>> Hi,
>>>>>
>>>>> I am using System.Windows.Forms.SaveFileDialog to prompt the user to
>>>>> select a file to which data is exported.
>>>>>
>>>>> I would like the control to always add the default extension, in
>>>>> this case .xls, to whatever filename the user enters - but the default
>>>>> behavior is that the extension is only added if the user has not
>>>>> already entered an extension.
>>>>> E.g. if the user types in the filename "export.txt" then the
>>>>> SaveFileDialog should append .xls to form "export.txt.xls".
>>>>>
>>>>> Of course I could just do this manually after the user has OK'd but
>>>>> then the dialog's prompt for create and overwrite won't be correct.
>>>>>
>>>>> How can I configure SaveFileDialog to ALWAYS append .xls?
>>>>>
>>>>> Below is a code snippet that I use to prompt the user for a
>>>>> filename:
>>>>>
>>>>> public static string GetExportFilename()
>>>>>
>>>>> {
>>>>>
>>>>> System.Windows.Forms.SaveFileDialog saveFileDialog = new
>>>>> SaveFileDialog();
>>>>>
>>>>> saveFileDialog.DefaultExt =
>>>>> "*.xls";
>>>>>
>>>>> saveFileDialog.Filter = "Excel
>>>>> 8.0+ (*.xls)|*.xls";
>>>>>
>>>>> saveFileDialog.AddExtension =
>>>>> true;
>>>>>
>>>>> saveFileDialog.CheckPathExists
>>>>> = true;
>>>>>
>>>>> saveFileDialog.CheckFileExists
>>>>> = false;
>>>>>
>>>>> saveFileDialog.CreatePrompt =
>>>>> true;
>>>>>
>>>>> saveFileDialog.OverwritePrompt
>>>>> = true;
>>>>>
>>>>> string exportFilename = "";
>>>>>
>>>>> if
>>>>> (saveFileDialog.ShowDialog() == DialogResult.OK)
>>>>>
>>>>> {
>>>>>
>>>>> exportFilename =
>>>>> saveFileDialog.FileName;
>>>>>
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> return exportFilename;
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> Regards
>>>>> Joubert
>>>
>>>
>>
>>
>
>