473,394 Members | 1,951 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,394 software developers and data experts.

Check for valid file names

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
3 14496
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Al Kolff | last post by:
Hi, Has anyone come across a utility to check the case of a filename versus a php page? I develop locally on a windows machine (Know Know) then upload to a Linux and everything works usually works...
9
by: Maciej Sobczak | last post by:
Hi, I have a string. This string is to be used as a path for a new file. I would like to check if this string *could be* a valid file name, *before* I try to create the file itself. In other...
37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
4
by: Henry Jia | last post by:
Hi, Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)? Thanks in advance! Henry
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
10
by: Academia | last post by:
I'd like to check a string to see that it is a valid file name. Is there a Like pattern or RegEx that can do that. 1) Just the file name with maybe an extension 2)A full path An help...
4
by: bizt | last post by:
Hi, Im looking for a regular expression to check that a entered filename is valid. I have a cms Im building where the user can enter the name of a file, enter content and then click Save where...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.