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. General Programming
  3. C#
  4. File/Directory Exists?

File/Directory Exists?

Scheduled Pinned Locked Moved C#
sysadminquestioncsharpwindows-adminregex
4 Posts 3 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.
  • T Offline
    T Offline
    tdciDoug
    wrote on last edited by
    #1

    This is really an ASP question, but since I'm using C#, I'll post it here. I'm having trouble accessing remote files (or directories) out of my application. I simply want to check if a file exists on the other machine, which is shared on the same network. No dice, always comes up false. I have set up the IUSR_ComputerName and IWAM_ComputerName accounts on the remote computer to match my IIS account. Still returns only false. I've mapped a drive to the network location, and then put that mapped drive into a virtual directory. In the IIS Administrator I can see the files I'm trying to reach through this virtual directory...but the application only returns false. Here's the code from my application: private void Page_Load(object sender, System.EventArgs e) { if (System.IO.Directory.Exists("Drive")) Response.Write(Server.MapPath("Drive") + " Exists "); else Response.Write(Server.MapPath("Drive") + " does not exist "); } Thanks for the help on this. If anybody knows another method of accomplishing this same task, I'm all ears. All I can report is that we don't want to run IIS on the remote machine, and we don't particularly want to spawn an application to take care of the file maintenance...we'd like for the code to handle it. :)

    S 1 Reply Last reply
    0
    • T tdciDoug

      This is really an ASP question, but since I'm using C#, I'll post it here. I'm having trouble accessing remote files (or directories) out of my application. I simply want to check if a file exists on the other machine, which is shared on the same network. No dice, always comes up false. I have set up the IUSR_ComputerName and IWAM_ComputerName accounts on the remote computer to match my IIS account. Still returns only false. I've mapped a drive to the network location, and then put that mapped drive into a virtual directory. In the IIS Administrator I can see the files I'm trying to reach through this virtual directory...but the application only returns false. Here's the code from my application: private void Page_Load(object sender, System.EventArgs e) { if (System.IO.Directory.Exists("Drive")) Response.Write(Server.MapPath("Drive") + " Exists "); else Response.Write(Server.MapPath("Drive") + " does not exist "); } Thanks for the help on this. If anybody knows another method of accomplishing this same task, I'm all ears. All I can report is that we don't want to run IIS on the remote machine, and we don't particularly want to spawn an application to take care of the file maintenance...we'd like for the code to handle it. :)

      S Offline
      S Offline
      SandeepN
      wrote on last edited by
      #2

      What is Drive ? in if (System.IO.Directory.Exists("Drive")) Please substitute "Drive" as "x:\\" should work..( where x is mapdrive letter) or if (System.IO.Directory.Exists("\\\\MachineName\\ShareName\\FolderName")) should do Sandeep Naik

      T 1 Reply Last reply
      0
      • S SandeepN

        What is Drive ? in if (System.IO.Directory.Exists("Drive")) Please substitute "Drive" as "x:\\" should work..( where x is mapdrive letter) or if (System.IO.Directory.Exists("\\\\MachineName\\ShareName\\FolderName")) should do Sandeep Naik

        T Offline
        T Offline
        tdciDoug
        wrote on last edited by
        #3

        Drive is the name of my virtual directory, which maps to what you call x:

        M 1 Reply Last reply
        0
        • T tdciDoug

          Drive is the name of my virtual directory, which maps to what you call x:

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          As Sandeep correctly mentioned, you're looking for the wrong directory. You need to wrap "Drive" in a call to Server.MapPath() as well when calling System.IO.Directory.Exists(), otherwise you're actually searching for a Direcory named "Drive" instead of the mapped one. Regards, mav

          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