确定驻留在网络文件服务器上的文件的可访问性 [英] Determine the accessibility of a file residing on a network file server

查看:62
本文介绍了确定驻留在网络文件服务器上的文件的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net中编写了代码,试图读取驻留在文件服务器上的文本文件.该例程应将文件内容发布到新页面上,或通知用户他/她无法访问该文件.授予/阻止访问的文件安全性是标准的NTFS安全性.我的问题是我需要根据用户读取文件的能力进行分支.我已经尝试过几次尝试评估用户对该文件的访问权限,但都失败了.鉴于我无法以推荐的方式分支代码,因此我恢复为尝试,捕获",希望我可以根据异常转移捕获中的代码.奇怪的是,我捕获的异常并没有根据文件的可访问性而有所不同.我尝试了以下方法来确定可访问性:

> Dim mytest  as  FileFtream = 新建文件流(myfile,fileMode.Open)
如果 mytest.CanRead 然后'抛出一个异常,我已经 无法 捕获 


--snip—

  Dim  FileExists  as   Boolean  = 错误
FileExists =(len(Dir(myfile,vbNormal))>  0 )'总是返回 True  没有没有例外


--snip--

 填写 as  FileInfo = 新建 FileInfo(myfile)
如果已存在文件,则然后'始终返回 true  



打开文件的方法:

 Response.Redirect(myfile, False )'总是抛出相同的异常,无论 of  span>是否已打开文件  


--Snip—

 System.Diagnostics.Process.start(myfile)'仅在Visual Studio调试中打开文件,但 http://vbcity.com/forums/t/163869.aspx  [ http://msdn.microsoft.com/en-us/library/8e1fc3b8.aspx#Y891  [^ ] 


感谢您的回复.我已经进行了测试但都失败了.我开始相信问题出在测试应用服务器上.我要求将其放置在已知成功的其他地方.


I’ve written code in vb.net that attempts to read a text file which resides on a file server. The routine should either post the contents of the file on a new page or inform the user the file is inaccessible by him/her. The file security that grants/prevents access is the standard NTFS security. My problem is that I need to branch based on the user’s ability to read the file. I’ve made several attempts to assess the use’s access to the file but they have failed. Given that I could not branch code the recommended way I reverted to "TRY, Catch" hoping that I could divert code in the catch based on the exception. Strangely, the exceptions I did catch did not vary based on the accessibility of the file. I’ve tried the following methods to determine the accessibility:

>Dim mytest as FileFtream  = New filestream(myfile, fileMode.Open) 
If mytest.CanRead  Then        ‘throws an exception I’ve not been able to catch


--snip—

Dim FileExists as Boolean = False
FileExists = (len(Dir(myfile, vbNormal)) > 0)    ‘always returns True with no exceptions


--snip--

Dim Fil as FileInfo = New FileInfo(myfile)
If fil.Exists then  ‘ always returns true



Methods to open file:

Response.Redirect(myfile, False)   ‘always throws the same exception regardless of whether the file is opened


--Snip—

System.Diagnostics.Process.start(myfile)  ‘opens the file only in Visual Studio debug but not from the test web server


Any Ideas? and yes, thanks for your time!

解决方案

Great sample code for Reading NT File & Folder Permissions
http://vbcity.com/forums/t/163869.aspx[Reading NT File & Folder Permissions]


Try:
http://msdn.microsoft.com/en-us/library/8e1fc3b8.aspx#Y891[^]


Thanks for you replys. I''ve but both to test but failed. I beginning to believe that the problem has resided in the test applications server. I''m making a request that it be placed elsewhere where there has been know success.


这篇关于确定驻留在网络文件服务器上的文件的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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