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. checking for file existence

checking for file existence

Scheduled Pinned Locked Moved C#
question
3 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.
  • P Offline
    P Offline
    ploxy
    wrote on last edited by
    #1

    how can i code to check for the existence of a particular text file in a drive and then call for a dialogue form if the file does not exist

    ma coding life

    M L 2 Replies Last reply
    0
    • P ploxy

      how can i code to check for the existence of a particular text file in a drive and then call for a dialogue form if the file does not exist

      ma coding life

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello,

      ploxy wrote:

      how can i code to check for the existence of a particular text file in a drive

      Have a look at System.IO.File namespace and "Exists" method.

      ploxy wrote:

      and then call for a dialogue form if the file does not exist

      The System.Windows.Forms.MessageBox with it's static "Show" method will do that. Hope it helps! All the best, Martin

      1 Reply Last reply
      0
      • P ploxy

        how can i code to check for the existence of a particular text file in a drive and then call for a dialogue form if the file does not exist

        ma coding life

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        if (!File.Exists(filename)) {
        filename=null;
        using (OpenFileDialog dlg=new OpenFileDialog()) {
        ... dlg properties = values;
        if (dlg.Show()==DialogResult.OK) filename=dlg.FileName;
        }
        }
        if (filename!=null) ... // read the file

        :)

        Luc Pattyn [My Articles] [Forum Guidelines]

        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