How do i use mshtml

Discussion in 'ASP .Net Building Controls' started by Mathew George, Jul 17, 2003.

  1. Hello,

    How do i use mshtml in asp for parsing an html file.
    Can anyone give the code in vb.....

    Mathew
     
    Mathew George, Jul 17, 2003
    #1
    1. Advertisements

  2. Mathew George

    Rob Mayo Guest

    Back when I was fooling around with this for the first time, I made a web app that had a textbox. Users would enter HTML in the box and submit the form to the page. I would then parse the images out of that page and save them. Here is a sample. You can start from there.



    Imports MSHTML
    Imports SHDocVw
    Public Class TestHTMLDOM
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim htmlDOM As IHTMLDocument2
    Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()

    brwTest.Navigate("about:blank")
    htmlDOM = brwTest.Document
    htmlDOM.body.innerHTML = Request.Form("HTMLSource")

    Dim objI As IHTMLElement
    For Each objI In htmlDOM.images
    objI.src = "/KnowledgeBase/Support/4/test.gif"
    Next

    Me.TextBox1.Text = htmlDOM.body.innerHTML

    htmlDOM = Nothing
    brwTest.Dispose()

    End Sub
    End Class
     
    Rob Mayo, Jul 18, 2003
    #2
    1. Advertisements

  3. I tried to ececute the same code given by rob, i got an error message.

    error message are as
    -----------------------------------------

    Server Error in '/NFTE' Application.
    --------------------------------------------------------------------------------

    Access is denied.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access is denied.

    The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is '{machinename}\ASPNET', which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

    To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.

    Source Error:


    Line 28: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Line 29: Dim htmlDOM As IHTMLDocument2
    Line 30: Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()



    -----------------------------------------------------

    I have given rights access to "{machinename}\ASPNET then also it gave me the same error.............
    Help please.

    Mathew

    Back when I was fooling around with this for the first time, I made a web app that had a textbox. Users would enter HTML in the box and submit the form to the page. I would then parse the images out of that page and save them. Here is a sample. You can start from there.



    Imports MSHTML
    Imports SHDocVw
    Public Class TestHTMLDOM
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim htmlDOM As IHTMLDocument2
    Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()

    brwTest.Navigate("about:blank")
    htmlDOM = brwTest.Document
    htmlDOM.body.innerHTML = Request.Form("HTMLSource")

    Dim objI As IHTMLElement
    For Each objI In htmlDOM.images
    objI.src = "/KnowledgeBase/Support/4/test.gif"
    Next

    Me.TextBox1.Text = htmlDOM.body.innerHTML

    htmlDOM = Nothing
    brwTest.Dispose()

    End Sub
    End Class
     
    Mathew George, Jul 18, 2003
    #3
  4. Mathew George

    Rob Mayo Guest

    try switching that back to webbrowser. I might have been screwing with something
    I tried to ececute the same code given by rob, i got an error message.

    error message are as
    -----------------------------------------

    Server Error in '/NFTE' Application.
    ------------------------------------------------------------------------------

    Access is denied.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access is denied.

    The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is '{machinename}\ASPNET', which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

    To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.

    Source Error:


    Line 28: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Line 29: Dim htmlDOM As IHTMLDocument2
    Line 30: Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()


    -----------------------------------------------------

    I have given rights access to "{machinename}\ASPNET then also it gave me the same error.............
    Help please.

    Mathew

    Back when I was fooling around with this for the first time, I made a web app that had a textbox. Users would enter HTML in the box and submit the form to the page. I would then parse the images out of that page and save them. Here is a sample. You can start from there.



    Imports MSHTML
    Imports SHDocVw
    Public Class TestHTMLDOM
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim htmlDOM As IHTMLDocument2
    Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()

    brwTest.Navigate("about:blank")
    htmlDOM = brwTest.Document
    htmlDOM.body.innerHTML = Request.Form("HTMLSource")

    Dim objI As IHTMLElement
    For Each objI In htmlDOM.images
    objI.src = "/KnowledgeBase/Support/4/test.gif"
    Next

    Me.TextBox1.Text = htmlDOM.body.innerHTML

    htmlDOM = Nothing
    brwTest.Dispose()

    End Sub
    End Class
     
    Rob Mayo, Jul 18, 2003
    #4
  5. Mathew George

    Rob Mayo Guest

    i also remember I had to make a COM interop for them. (probably a given)
    I tried to ececute the same code given by rob, i got an error message.

    error message are as
    -----------------------------------------

    Server Error in '/NFTE' Application.
    ------------------------------------------------------------------------------

    Access is denied.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access is denied.

    The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is '{machinename}\ASPNET', which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

    To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.

    Source Error:


    Line 28: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Line 29: Dim htmlDOM As IHTMLDocument2
    Line 30: Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()


    -----------------------------------------------------

    I have given rights access to "{machinename}\ASPNET then also it gave me the same error.............
    Help please.

    Mathew

    Back when I was fooling around with this for the first time, I made a web app that had a textbox. Users would enter HTML in the box and submit the form to the page. I would then parse the images out of that page and save them. Here is a sample. You can start from there.



    Imports MSHTML
    Imports SHDocVw
    Public Class TestHTMLDOM
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim htmlDOM As IHTMLDocument2
    Dim brwTest As New SHDocVw.InternetExplorer() 'WebBrowser()

    brwTest.Navigate("about:blank")
    htmlDOM = brwTest.Document
    htmlDOM.body.innerHTML = Request.Form("HTMLSource")

    Dim objI As IHTMLElement
    For Each objI In htmlDOM.images
    objI.src = "/KnowledgeBase/Support/4/test.gif"
    Next

    Me.TextBox1.Text = htmlDOM.body.innerHTML

    htmlDOM = Nothing
    brwTest.Dispose()

    End Sub
    End Class
     
    Rob Mayo, Jul 19, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.