Link to home
Start Free TrialLog in
Avatar of xenia27
xenia27Flag for Taiwan, Province of China

asked on

Accessing Network Drive

Hi,

How can I access a known network drive and read all the files in the drive?
Under this directory
\\Server\Directory1\
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 experts-exchange.com...but I still have no clue how can I make this work.  Please help me~~
ASKER CERTIFIED SOLUTION
Avatar of Expert1701
Expert1701

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenia27

ASKER

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?
Avatar of Expert1701
Expert1701

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.
  }
Avatar of xenia27

ASKER

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.
Avatar of xenia27

ASKER

OK...Thanks for your help.  I guess I know how to do my work now.  ^^
You're welcome.  Good luck!