By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,218 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

Check for valid file names

P: n/a
Hi,

In C# I tried to save a file from a generated file name.
Just before launching the dialog I check for a valid file
name to be sure.

There for I used the method ValidateNames from the save
dialog.

The strange thing is that sometimes the save dialogue
crashes on invalid file names (containing chars like ] ),
but the method ValidateNames return true.

Code looks like:
saveFileDialog = new System.Windows.Forms.SaveFileDialog();

saveFileDialog.FileName = (...) <--- generated file name
may contan invalid chars

if (!saveFileDialog.ValidateNames) <-- method returns true
for invalid file names ??

{

saveFileDialog.FileName =
"MyChart."+saveFileDialog.DefaultExt; <-- if name is
invalid, supply valid file name as default

}

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

{

}

Any idea what may be wrong ?

Thanks.

Bye

Chris



Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ValidateNames is a property, not a method.
You need to initially set this to true, then the names will be validated.

By the way, the character ] is a valid character in a filename.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Chris" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Hi,

In C# I tried to save a file from a generated file name.
Just before launching the dialog I check for a valid file
name to be sure.

There for I used the method ValidateNames from the save
dialog.

The strange thing is that sometimes the save dialogue
crashes on invalid file names (containing chars like ] ),
but the method ValidateNames return true.

Code looks like:
saveFileDialog = new System.Windows.Forms.SaveFileDialog();

saveFileDialog.FileName = (...) <--- generated file name
may contan invalid chars

if (!saveFileDialog.ValidateNames) <-- method returns true
for invalid file names ??

{

saveFileDialog.FileName =
"MyChart."+saveFileDialog.DefaultExt; <-- if name is
invalid, supply valid file name as default

}

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

{

}

Any idea what may be wrong ?

Thanks.

Bye

Chris


Nov 16 '05 #2

P: n/a
Thanks .. you are right.

But if I set that property ValidateNames on true, and so C#
wil check for valid file names, how can I check a priori if
my file name is valid. In order to replace it with a valid
default file name.

In C# there must be a simple method for that I guess ...

Some help woud be nice ...

Bye,

Chris
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:eH**************@TK2MSFTNGP14.phx.gbl...
ValidateNames is a property, not a method.
You need to initially set this to true, then the names will be validated.
By the way, the character ] is a valid character in a filename.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Chris" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Hi,

In C# I tried to save a file from a generated file name.
Just before launching the dialog I check for a valid file name to be sure.

There for I used the method ValidateNames from the save
dialog.

The strange thing is that sometimes the save dialogue
crashes on invalid file names (containing chars like ] ), but the method ValidateNames return true.

Code looks like:
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.FileName = (...) <--- generated file name may contan invalid chars

if (!saveFileDialog.ValidateNames) <-- method returns true for invalid file names ??

{

saveFileDialog.FileName =
"MyChart."+saveFileDialog.DefaultExt; <-- if name is
invalid, supply valid file name as default

}

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

{

}

Any idea what may be wrong ?

Thanks.

Bye

Chris




Nov 16 '05 #3

P: n/a
I do not know of any particular feature that does that.
You would have to write your own function to test your filename.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Chris" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
Thanks .. you are right.

But if I set that property ValidateNames on true, and so C#
wil check for valid file names, how can I check a priori if
my file name is valid. In order to replace it with a valid
default file name.

In C# there must be a simple method for that I guess ...

Some help woud be nice ...

Bye,

Chris
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:eH**************@TK2MSFTNGP14.phx.gbl...
ValidateNames is a property, not a method.
You need to initially set this to true, then the names

will be validated.

By the way, the character ] is a valid character in a

filename.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Chris" <An*****@work.nl> wrote in message
news:11***************@wgsvr01.wldelft.nl...
> Hi,
>
> In C# I tried to save a file from a generated file name.
> Just before launching the dialog I check for a valid file > name to be sure.
>
> There for I used the method ValidateNames from the save
> dialog.
>
> The strange thing is that sometimes the save dialogue
> crashes on invalid file names (containing chars like ] ), > but the method ValidateNames return true.
>
> Code looks like:
> saveFileDialog = new System.Windows.Forms.SaveFileDialog(); >
> saveFileDialog.FileName = (...) <--- generated file name > may contan invalid chars
>
> if (!saveFileDialog.ValidateNames) <-- method returns true > for invalid file names ??
>
> {
>
> saveFileDialog.FileName =
> "MyChart."+saveFileDialog.DefaultExt; <-- if name is
> invalid, supply valid file name as default
>
> }
>
> if (saveFileDialog.ShowDialog() == DialogResult.OK)
>
> {
>
> }
>
>
>
> Any idea what may be wrong ?
>
> Thanks.
>
> Bye
>
> Chris
>
>
>
>
>
>
>


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.