Solved

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

Posted on 2013-12-30
3
707 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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