PC Review


Reply
Thread Tools Rate Thread

Check for valid file names

 
 
Chris
Guest
Posts: n/a
 
      9th Feb 2005
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







 
Reply With Quote
 
 
 
 
Dennis Myrén
Guest
Posts: n/a
 
      9th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>
>
>



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      9th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >
> >
> >
> >
> >
> >

>
>


 
Reply With Quote
 
Dennis Myrén
Guest
Posts: n/a
 
      9th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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
>> >
>> >
>> >
>> >
>> >
>> >
>> >

>>
>>

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check a string to see that it is a valid file name Academia Microsoft VB .NET 10 22nd Nov 2007 05:52 PM
What's the most efficient to check a file name is valid? =?Utf-8?B?Um9iZXJ0IE11bHJvbmV5?= Microsoft Excel Programming 14 3rd Nov 2005 01:59 AM
Masking valid file names ~toki Microsoft C# .NET 3 28th Mar 2004 09:06 AM
check for valid file pabs Microsoft Excel Programming 2 15th Jan 2004 06:52 AM
check if file path is valid dave Microsoft VB .NET 4 23rd Nov 2003 01:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:46 AM.