Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-12-30
3
Medium Priority
?
911 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 36

Accepted Solution

by:
Miguel Oz earned 1600 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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Loops Section Overview
Screencast - Getting to Know the Pipeline

886 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