Solved

How can I read all files content from directory vb.net

Posted on 2013-12-30
3
817 Views
Last Modified: 2014-01-02
I am going through all the folders in the .Net application and if the file is .aspx I want to read the body contents and save it in the variable.

1.Getting all the folder names under .Net application.
2.Reading the files under the folder name
3.If the file name is .aspx ,reading the the contents inside the body tag and saving it in a variable

How to do this.

Thanks
0
Comment
Question by:KavyaVS
[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
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 400 total points
ID: 39747030
I modified your requirements slightly to get only the aspx files from the target folder ( No need to loop all files if only aspx are required)
    Private Sub GetBodiesFromFolder(ByVal folder As String)
        Dim Files As String() = System.IO.Directory.GetFiles(folder, "*.aspx")
        For Each sFile As String In Files
            Dim fileCont As String = System.IO.File.ReadAllText(sFile)
            Dim startIndex = fileCont.IndexOf("<body>")
            If startIndex > 0 Then 'body tag found
                Dim endIndex = fileCont.IndexOf("</body>", startIndex)
                startIndex = startIndex + 6 'offset to skip body tag
                Dim body As String = fileCont.Substring(startIndex, endIndex - startIndex)
                Debug.WriteLine(body) 'Print body contents
            End If
        Next
    End Sub

Open in new window

0
 
LVL 3

Assisted Solution

by:Detlef001
Detlef001 earned 100 total points
ID: 39747915
Please have a look at these links for the same. These links would help you to aim your specific queries.

http://goo.gl/kGL9iC

http://goo.gl/OAEJMk

http://goo.gl/ylwO4f

Thanks.
0
 

Author Closing Comment

by:KavyaVS
ID: 39751654
Thanks
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
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

623 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