Solved

Accessing Network Drive

Posted on 2006-11-05
7
181 Views
Last Modified: 2010-04-16
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~~
0
Comment
Question by:xenia27
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17879152
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?
0
 

Author Comment

by:xenia27
ID: 17879165
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?
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17879183
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.
  }
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:xenia27
ID: 17879191
More question~  How can I delete files in this particular network drive??  Can I delete them?
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17879201
You can do this using the System.IO.File.Delete(string) method.
0
 

Author Comment

by:xenia27
ID: 17879204
OK...Thanks for your help.  I guess I know how to do my work now.  ^^
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17879211
You're welcome.  Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now