简体   繁体   中英

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. However, our videos are not stored on the C drive, but on the D drive instead.

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.

Could someone point me in the right direction on how to check in the D drive of the remote server

In UNC paths, drives are represented by a $. That is, 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).

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). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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