Solved

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

Posted on 2013-12-30
3
633 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now