如果File.Exists Else问题 [英] If File.Exists Else question

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

问题描述

如果我在VB.NET表单中使用下面的代码,即使文件存在,然后执行

,Else语句也会生成抱歉找不到文件

错误信息。


永远不会调用MessageBox.Show(StrPathToScript)!为什么?


如果File.Exists(StrPathToScript)那么


MessageBox.Show(StrPathToScript)


Else


MessageBox.Show(抱歉找不到文件)


结束如果


提前致谢


Joseph

If I use the code below in a VB.NET form, even if the file exists, and is
then executed, the Else statement produces the "Sorry cannot find the File "
error message.

The MessageBox.Show( StrPathToScript ) never gets called! why?

If File.Exists( StrPathToScript ) Then

MessageBox.Show( StrPathToScript )

Else

MessageBox.Show( "Sorry cannot find the File " )

End If

Thanks in advance

Joseph

推荐答案

Joseph,


来自MSDN文档:如果调用者没有足够的权限来读取指定的文件,则不会抛出任何异常并且方法返回false

无论路径是否存在


这可能是你的问题吗?


-

Carsten Thomsen

社区 - http://community.integratedsolutions.dk


" Joseph Oget" < pH值********** @ hotmail.com>在消息中写道

新闻:eK ************** @ TK2MSFTNGP14.phx.gbl ...
Joseph,

From the MSDN docs: "If the caller does not have sufficient permissions to
read the specified file, no exception is thrown and the method returns false
regardless of the existence of path"

Could that be your problem?

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"Joseph Oget" <ph**********@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
如果我使用代码在VB.NET表单下面,即使该文件存在,然后执行,Else语句也会生成抱歉找不到文件
。错误信息。

MessageBox.Show(StrPathToScript)永远不会被调用!为什么?

如果File.Exists(StrPathToScript)那么就是MessageBox.Show(StrPathToScript)

另外的消息盒.Show(抱歉找不到文件)

结束如果

提前致谢

Joseph
If I use the code below in a VB.NET form, even if the file exists, and is
then executed, the Else statement produces the "Sorry cannot find the File
" error message.

The MessageBox.Show( StrPathToScript ) never gets called! why?

If File.Exists( StrPathToScript ) Then

MessageBox.Show( StrPathToScript )

Else

MessageBox.Show( "Sorry cannot find the File " )

End If

Thanks in advance

Joseph


你好CT,



我试图检查的文件我的电脑本地存在,并且在汇编所在的

文件夹中,所以我试图以任何方式打开它,

只检查如果它存在或不存在。


Joseph

" CT" < CA ****** @ spammersgoawayintegrasol.dk>在消息中写道

新闻:O2 ************* @ TK2MSFTNGP09.phx.gbl ...
Hi CT,

Thanks for your reply.

The file I attempt to check the existence of, is local to my PC, and in a
folder below where the assembly is, so I do attempt to open it in any way,
only to check if it exist or not.

Joseph
"CT" <ca******@spammersgoawayintegrasol.dk> wrote in message
news:O2*************@TK2MSFTNGP09.phx.gbl...
Joseph,

来自MSDN文档:如果调用者没有足够的权限来读取指定的文件,则不会抛出任何异常,并且无论路径是否存在,该方法都返回
br />
这可能是你的问题吗?

- Carsten Thomsen
社区 - http://community.integratedsolutions.dk

Joseph Oget < pH值********** @ hotmail.com>在消息中写道
新闻:eK ************** @ TK2MSFTNGP14.phx.gbl ...
Joseph,

From the MSDN docs: "If the caller does not have sufficient permissions to
read the specified file, no exception is thrown and the method returns
false regardless of the existence of path"

Could that be your problem?

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"Joseph Oget" <ph**********@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
如果我在VB中使用下面的代码.NET表单,即使文件存在,然后执行
,Else语句也会生成抱歉无法找到
文件。错误信息。

MessageBox.Show(StrPathToScript)永远不会被调用!为什么?

如果File.Exists(StrPathToScript)那么就是MessageBox.Show(StrPathToScript)

另外的消息盒.Show(抱歉找不到文件)

结束如果

提前致谢

Joseph
If I use the code below in a VB.NET form, even if the file exists, and
is then executed, the Else statement produces the "Sorry cannot find the
File " error message.

The MessageBox.Show( StrPathToScript ) never gets called! why?

If File.Exists( StrPathToScript ) Then

MessageBox.Show( StrPathToScript )

Else

MessageBox.Show( "Sorry cannot find the File " )

End If

Thanks in advance

Joseph



即使现在或现在也可能没有足够的权利。

如何处理异常?否则我会仔细查看路径并尝试

a位置,我确定没有问题...


-

Patrice


" Joseph Oget" < pH值********** @ hotmail.com>一个écritdansle message de

新闻:O9 **************** @ TK2MSFTNGP15.phx.gbl ...
Could also not have sufficient rights to even now if it exists or now. How
do you handle exceptions ? Else I would double check the path and would try
a location where I''m sure there is no problems...

--
Patrice

"Joseph Oget" <ph**********@hotmail.com> a écrit dans le message de
news:O9****************@TK2MSFTNGP15.phx.gbl...
您好CT,

感谢您的回复。

我试图检查存在的文件是我的电脑本地文件,并在下面的
文件夹中组装是,所以我试图以任何方式打开它,
只检查它是否存在。

约瑟夫
CT < CA ****** @ spammersgoawayintegrasol.dk>在消息中写道
新闻:O2 ************* @ TK2MSFTNGP09.phx.gbl ...
Hi CT,

Thanks for your reply.

The file I attempt to check the existence of, is local to my PC, and in a
folder below where the assembly is, so I do attempt to open it in any way,
only to check if it exist or not.

Joseph
"CT" <ca******@spammersgoawayintegrasol.dk> wrote in message
news:O2*************@TK2MSFTNGP09.phx.gbl...
Joseph,

从MSDN文档中:如果调用者没有足够的权限
来读取指定的文件,则不会抛出任何异常,并且无论路径是否存在,该方法都会返回错误
<这可能是你的问题吗?

-
Carsten Thomsen
社区 - http://community.integratedsolutions.dk

Joseph Oget < pH值********** @ hotmail.com>在消息中写道
新闻:eK ************** @ TK2MSFTNGP14.phx.gbl ...
Joseph,

From the MSDN docs: "If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns
false regardless of the existence of path"

Could that be your problem?

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"Joseph Oget" <ph**********@hotmail.com> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
如果我在VB中使用下面的代码.NET表单,即使该文件存在,然后执行
,Else语句也会生成抱歉找不到
文件。错误信息。

MessageBox.Show(StrPathToScript)永远不会被调用!为什么?

如果File.Exists(StrPathToScript)那么就是MessageBox.Show(StrPathToScript)

另外的消息盒.Show(抱歉找不到文件)

结束如果

提前致谢

Joseph
If I use the code below in a VB.NET form, even if the file exists, and
is then executed, the Else statement produces the "Sorry cannot find the File " error message.

The MessageBox.Show( StrPathToScript ) never gets called! why?

If File.Exists( StrPathToScript ) Then

MessageBox.Show( StrPathToScript )

Else

MessageBox.Show( "Sorry cannot find the File " )

End If

Thanks in advance

Joseph




这篇关于如果File.Exists Else问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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