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. C# file exists on network drive

C# file exists on network drive

Scheduled Pinned Locked Moved C#
csharpdatabasesysadminhelpquestion
8 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.
  • C Offline
    C Offline
    classy_dog
    wrote on last edited by
    #1

    In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:

    using System.IO

    if (!File.Exists(myfile))
    Console.WriteLine("The file does not exists.");

    The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?

    S L 2 Replies Last reply
    0
    • C classy_dog

      In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:

      using System.IO

      if (!File.Exists(myfile))
      Console.WriteLine("The file does not exists.");

      The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?

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

      The first thing I see is that your sample path you provided is wrong. You are using the wrong slash in the path, it should be "\\servername\mdain\myfile.xls". The second thing I would check is if the computer you are running the application on has permissions to access the network drive, since that would return false regardless of the file existing.

      L 1 Reply Last reply
      0
      • S s_magus

        The first thing I see is that your sample path you provided is wrong. You are using the wrong slash in the path, it should be "\\servername\mdain\myfile.xls". The second thing I would check is if the computer you are running the application on has permissions to access the network drive, since that would return false regardless of the file existing.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Forward slashes are fine in path names; Windows correctly interprets them.

        Use the best guess

        L 1 Reply Last reply
        0
        • C classy_dog

          In a C# 2008 desktop application, the application is having a problem determining if a folder exists on a network drive. I am using code that looks like the following:

          using System.IO

          if (!File.Exists(myfile))
          Console.WriteLine("The file does not exists.");

          The value for the directory comes from a column in the database that looks like the following: //servername/mdain/myfile.xls". Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I'm not sure how easy that would be but perhaps the DirectoryInfo[^] or FileInfo[^] classes would help.

          Use the best guess

          C 1 Reply Last reply
          0
          • L Lost User

            Forward slashes are fine in path names; Windows correctly interprets them.

            Use the best guess

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Richard MacCutchan wrote:

            Forward slashes are fine in path names; Windows correctly interprets them.

            Windows, yes. Most apps do not.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            L 1 Reply Last reply
            0
            • L Lost User

              Richard MacCutchan wrote:

              Forward slashes are fine in path names; Windows correctly interprets them.

              Windows, yes. Most apps do not.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Eddy Vluggen wrote:

              Most apps do not.

              Well, you would not expect Microsoft's apps to do things properly, would you?

              Use the best guess

              L 1 Reply Last reply
              0
              • L Lost User

                Eddy Vluggen wrote:

                Most apps do not.

                Well, you would not expect Microsoft's apps to do things properly, would you?

                Use the best guess

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Richard MacCutchan wrote:

                Well, you would not expect Microsoft's apps to do things properly, would you?

                If I wouldn't, I'd be recommending to use GNU/C, OpenOffice, MySql and black magic. Still I recommend to pay up for Microsofts' apps :)

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                1 Reply Last reply
                0
                • L Lost User

                  I'm not sure how easy that would be but perhaps the DirectoryInfo[^] or FileInfo[^] classes would help.

                  Use the best guess

                  C Offline
                  C Offline
                  classy_dog
                  wrote on last edited by
                  #8

                  Thanks! this works!

                  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