文件名
问题描述:
如何使用.NET 1.1检查字符串是否包含有效文件名
for winxp?
有问题的应用程序有一个文本框,用户可以在其中输入
filename和文件名。它不应该被允许输入路径
+ filename就像c:\ tmp \ myfile.log"或相对路径.. \tmp
\ myfile.log" - 不应该允许目录信息,只允许文件名。
任何建议。
Hi,
How can check using .NET 1.1 that a string contains a valid filename
for winxp?
The application in question has a textbox where user can enter
filename and only the filename. It should not allowed to enter path
+filename like "c:\tmp\myfile.log" or relative paths "..\tmp
\myfile.log" - no directory info should be allowed, only the filename.
Any suggestions.
答
if( File.Exists(filePathFromTextBox))
{
//工作
}
其他
{
//显示错误
}
存在从早期开始就存在。我相信它是1.0。这肯定是1.1:
http://msdn.microsoft.com/en-us/libr...rs(VS.71).aspx
-
Gregory A. Beamer
MVP,MCP:+ I,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或只是阅读它:
http://feeds.feedburner.com/GregoryBeamer
********************* ***********************
|创造性思考! |
***************************************** ***
" RedLars" < Li *********** @ gmail.com写信息
新闻:9e ******************* *************** @ x35g2000 hsb.googlegroups.com ...
if(File.Exists(filePathFromTextBox))
{
//Do work
}
else
{
//Display error
}
Exists has been around since the early days. I believe it was 1.0. It was
definitely 1.1:
http://msdn.microsoft.com/en-us/libr...rs(VS.71).aspx
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"RedLars" <Li***********@gmail.comwrote in message
news:9e**********************************@x35g2000 hsb.googlegroups.com...
如何使用.NET 1.1检查字符串是否包含有效文件名
for winxp?
有问题的应用程序有一个文本框,其中用户可以输入
文件名,只输入文件名。它不应该被允许输入路径
+ filename就像c:\ tmp \ myfile.log"或相对路径.. \tmp
\ myfile.log" - 不应该允许目录信息,只允许文件名。
任何建议。
Hi,
How can check using .NET 1.1 that a string contains a valid filename
for winxp?
The application in question has a textbox where user can enter
filename and only the filename. It should not allowed to enter path
+filename like "c:\tmp\myfile.log" or relative paths "..\tmp
\myfile.log" - no directory info should be allowed, only the filename.
Any suggestions.
你应该只需要检查字符串是否包含任何无效的文件名
字符由Path.GetInvalidFilenameChars返回。 />
http: //msdn.microsoft.com/en-us/libr...namechars.aspx
" RedLars"写道:
You should just need to check if the string contains any invalid filename
characters as returned by Path.GetInvalidFilenameChars.
http://msdn.microsoft.com/en-us/libr...namechars.aspx
"RedLars" wrote:
如何使用.NET 1.1检查字符串是否包含有效文件名
for winxp?
有问题的应用程序有一个文本框,用户可以输入
filename和文件名。它不应该被允许输入路径
+ filename就像c:\ tmp \ myfile.log"或相对路径.. \tmp
\ myfile.log" - 不应该允许目录信息,只允许文件名。
任何建议。
Hi,
How can check using .NET 1.1 that a string contains a valid filename
for winxp?
The application in question has a textbox where user can enter
filename and only the filename. It should not allowed to enter path
+filename like "c:\tmp\myfile.log" or relative paths "..\tmp
\myfile.log" - no directory info should be allowed, only the filename.
Any suggestions.
9月24日, 9:45 * am,RedLars< Liverpool1 ... @ gmail.comwrote:
On Sep 24, 9:45*am, RedLars <Liverpool1...@gmail.comwrote:
怎么样使用.NET 1.1检查字符串是否包含有效文件名
for winxp?
有问题的应用程序有一个文本框,用户可以在其中输入
filename,只有文件名。它不应该被允许输入路径
+ filename就像c:\ tmp \ myfile.log"或相对路径.. \tmp
\ myfile.log" - 不应该允许目录信息,只允许文件名。
任何建议。
Hi,
How can check using .NET 1.1 that a string contains a valid filename
for winxp?
The application in question has a textbox where user can enter
filename and only the filename. It should not allowed to enter path
+filename like "c:\tmp\myfile.log" or relative paths "..\tmp
\myfile.log" - no directory info should be allowed, only the filename.
Any suggestions.
只需检查你的字符串,确保没有出现\
..IndexOf(" \");
Just check your string to make sure there are no occurences of \
..IndexOf("\");