Solved

Accessing Network Drive

Posted on 2006-11-05
7
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:Expert1701
Comment Utility
You're welcome.  Good luck!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now