Solved

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

Posted on 2013-12-30
3
683 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
3 Comments
 
LVL 35

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

778 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