文件名 [英] filename

查看:106
本文介绍了文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何使用.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("\");


这篇关于文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆