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> </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> </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 - 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 SaveFileDialog should append .xls to form=20
"export.txt.xls".</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT> </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> </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> </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> </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"> &nbs=
p; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =20
</SPAN>saveFileDialog.OverwritePrompt =3D <SPAN=20
style=3D"COLOR: blue">true</SPAN>;<SPAN=20
style=3D"mso-tab-count: =
3"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =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"> &nbs=
p;  =
; =
=20
</SPAN>exportFilename =3D saveFileDialog.FileName;<SPAN=20
style=3D"mso-tab-count: =
5"> &nbs=
p;  =
; =
&=
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"> &nbs=
p;  =
; =
=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"> &nbs=
p;  =
; =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> </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"> &nbs=
p;  =
; =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"> &nbs=
p; =20
</SPAN>}</SPAN></P></FONT></DIV></BLOCKQUOTE>
<DIV><FONT face=3DVerdana size=3D2></FONT> </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--