Solved

Accessing Network Drive

Posted on 2006-11-05
7
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

626 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