简体   繁体   English

检查文件在远程服务器和各种驱动器上是否存在

[英]Check if file exists on remote server and various drive

We have an aspx page that needs to check if video files exist on our video server and display a link if the file does exist. 我们有一个aspx页面,需要检查我们的视频服务器上是否存在视频文件,如果文件确实存在,则显示一个链接。 However, our videos are not stored on the C drive, but on the D drive instead. 但是,我们的视频不是存储在C驱动器上,而是存储在D驱动器上。

I have tried 我努力了

System.IO.File.Exists(@"http://ourvideoserver/pcode/videofile_name.mp4") and 
System.IO.File.Exists(@"\\ourvideoserver\\D:\\pcode\\videofile_name.mp4")

the last one was just taking a wild guess 最后一个只是一个疯狂的猜测

And I cannot figure out how to check the files on a remote server on a different drive than C. 而且我不知道如何检查与C不同的驱动器上的远程服务器上的文件。

Could someone point me in the right direction on how to check in the D drive of the remote server 有人可以向我指出有关如何检入远程服务器D驱动器的正确方向

In UNC paths, drives are represented by a $. 在UNC路径中,驱动器用$表示。 That is, D$. 即D $。 Try this: 尝试这个:

System.IO.File.Exists(@"\\ourvideoserver\D$\pcode\videofile_name.mp4")

So, something like this should work (it does when I run it as a unit test with a change in the server name). 因此,这样的事情应该可以工作(当我将其作为更改服务器名称的单元测试来运行时,它可以工作)。

[TestMethod]
public void CheckUNCFileExists()
{
      Assert.AreEqual(true, File.Exists("\\\\fileserver\\documents\\file.txt"));
      Assert.AreEqual(true, File.Exists(@"\\fileserver\documents\file.txt"));
}

One thing that you might want to check is the name of the actual share, using an administrative command prompt on the file server (in my case it is the "documents" share): 您可能要检查的一件事是实际共享的名称,使用文件服务器上的管理命令提示符(在我的情况下,它是“文档”共享):

C:\Windows\system32>net share

Share name   Resource                        Remark

-------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\Windows                      Remote Admin
documents    C:\documents
The command completed successfully.

If the path seems ok (and you can get to it with Windows Explorer), another thing to investigate is whether the application pool identity of your web application (probably you if you are debugging on your desktop using something like Visual Studio, or whatever your IIS admin configures on the web server side) has read access to the share (for windows sharing permissions) and read access (via NTFS permissions) on the folder/file (also, depending on how paranoid your admins are, you might also need "traverse" permissions on higher folders). 如果路径看起来不错(您可以使用Windows资源管理器进行访问),则需要调查的另一件事是您的Web应用程序的应用程序池标识(如果您是使用Visual Studio之类的工具在桌面上调试的,则可能是您) IIS管理员在Web服务器端进行配置)具有对共享的读取访问权限(用于Windows共享权限)和对文件夹/文件的读取访问权限(通过NTFS权限)(此外,根据管理员的偏执程度,您可能还需要“遍历”在更高文件夹上的权限)。

If you can't get to it with Windows Explorer, and you are using an administrative share (ex c$, d$, etc), you should re-share the folder with a different share name (since this will allow you to change permissions to make it readable by you/and the IIS application pool identity). 如果您无法使用Windows资源管理器访问该文件夹,并且您正在使用管理共享(例如c $,d $等),则应使用其他共享名重新共享该文件夹(因为这样可以更改使您(和IIS应用程序池标识)可读的权限。 If you are really bent on using the administrative share name, you'll have to modify permissions of the administrative share and may need to undertake something like this: 如果您真的想使用管理共享名,则必须修改管理共享的权限,并且可能需要执行以下操作:

http://support.microsoft.com/kb/971277 http://support.microsoft.com/kb/971277

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM