Problem with FileInfo.Exist and network access
-
Hello guys, I have a lot of documents in filesystem of a web server (1). An other web server (2) should offer access to this documents too. That works fine and my generated links to the documents will load the document inside the browser. My problem is, the documents (the name, not the data !!!) and the path are administer in a database and I have a test, if the document exist, before I provide the link. The code for test is follows:
fi = New FileInfo(strPhysPath) If fi.Exists = False Then ' do an error message here else ' generate a link end if
For this check I need a physical path and I have it in different ways. As "normal path" (i.e. "x:\documents\pdf\test.pdf"), if the code runs on web server1 (the server, where the documents are stored), as UNC-Path to a shared folder (i.e. "\\server1\documents\pdf\test.pdf") and/or as a network drive path using the shared folder (i.e. "y:\pdf\test.pdf" where y: -> \\server1\documents). The last both variants I must use on web server2 and here I get always: File not exist using the code above. No errors, no execptions. Why? Did anybody have other ideas ? Thank you very much Stephan
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_) -
Hello guys, I have a lot of documents in filesystem of a web server (1). An other web server (2) should offer access to this documents too. That works fine and my generated links to the documents will load the document inside the browser. My problem is, the documents (the name, not the data !!!) and the path are administer in a database and I have a test, if the document exist, before I provide the link. The code for test is follows:
fi = New FileInfo(strPhysPath) If fi.Exists = False Then ' do an error message here else ' generate a link end if
For this check I need a physical path and I have it in different ways. As "normal path" (i.e. "x:\documents\pdf\test.pdf"), if the code runs on web server1 (the server, where the documents are stored), as UNC-Path to a shared folder (i.e. "\\server1\documents\pdf\test.pdf") and/or as a network drive path using the shared folder (i.e. "y:\pdf\test.pdf" where y: -> \\server1\documents). The last both variants I must use on web server2 and here I get always: File not exist using the code above. No errors, no execptions. Why? Did anybody have other ideas ? Thank you very much Stephan
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)Well, If you are using a normal default app pool for this website most likely you are trying to access these files with the aspnet user. My guess would be that this user does not have file permissions to read the directory. NOTE if you do give aspnet user read permissions to the directory it can be a security issue. The only other thing I can think of is using the System.IO.File.Exists instead of using the FileInfo class. Hope that helps. Ben
-
Well, If you are using a normal default app pool for this website most likely you are trying to access these files with the aspnet user. My guess would be that this user does not have file permissions to read the directory. NOTE if you do give aspnet user read permissions to the directory it can be a security issue. The only other thing I can think of is using the System.IO.File.Exists instead of using the FileInfo class. Hope that helps. Ben
Hello Ben, An application pool is it not and this is not possible. Your second idea works, but I have also a test for the filelength (System.IO.FileInfo.Length). Did you have an idea to change this part too? Thanks Stephan
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_) -
Hello Ben, An application pool is it not and this is not possible. Your second idea works, but I have also a test for the filelength (System.IO.FileInfo.Length). Did you have an idea to change this part too? Thanks Stephan
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)