Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with FileInfo.Exist and network access

Problem with FileInfo.Exist and network access

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpdatabasequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Pilz
    wrote on last edited by
    #1

    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 ( )
    ( ) ) /
    \ ( (_/
    \_)

    K 1 Reply Last reply
    0
    • S Stephan Pilz

      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 ( )
      ( ) ) /
      \ ( (_/
      \_)

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • K kubben

        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

        S Offline
        S Offline
        Stephan Pilz
        wrote on last edited by
        #3

        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 ( )
        ( ) ) /
        \ ( (_/
        \_)

        K 1 Reply Last reply
        0
        • S Stephan Pilz

          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 ( )
          ( ) ) /
          \ ( (_/
          \_)

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          Since you are using VB.net you can try: Dim MySize As Long ' Returns file length (bytes). MySize = FileLen("TESTFILE") Otherwise you are stuck with the FileInfo Class Ben

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups