Accessing Network Drive


How can I access a known network drive and read all the files in the drive?
Under this directory
I have several files...text1.xml, text2.xml...text10.xml
How can I get all the files in this network drive?
Also, how can I change folders in the same network drive?

I've search all the articles in I still have no clue how can I make this work.  Please help me~~
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Expert1701Connect With a Mentor Commented:
You can get a list (string[]) of the files as simply as calling, System.IO.Directory.GetFiles(@"\\Server\Directory1").  What would you like to do with the files?
xenia27Author Commented:
I will probably have severl log file...and I need to open this file and search for some particular strings and parse them.  How can I read them?
Everything you need to do this can be found in the System.IO, and the System.Text.RegularExpressions namespaces.  Here is a quick example on opening each of the files in that directory:

  foreach (string file in System.IO.Directory.GetFiles(@"\\Server\Directory1"))
    string data;
    using (System.IO.StreamReader reader = new System.IO.StreamReader(file))
      data = reader.ReadToEnd();

    //Work with "data" here.
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

xenia27Author Commented:
More question~  How can I delete files in this particular network drive??  Can I delete them?
You can do this using the System.IO.File.Delete(string) method.
xenia27Author Commented:
OK...Thanks for your help.  I guess I know how to do my work now.  ^^
You're welcome.  Good luck!
All Courses

From novice to tech pro — start learning today.