Click here to Skip to main content
15,901,505 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionIsNumeric Pin
Uma Kameswari25-Jun-06 18:07
Uma Kameswari25-Jun-06 18:07 
AnswerRe: IsNumeric Pin
Aurelius166427-Jun-06 14:02
Aurelius166427-Jun-06 14:02 
Question"bubble event" Pin
ravikiranreddydharmannagari25-Jun-06 17:58
ravikiranreddydharmannagari25-Jun-06 17:58 
QuestionCreate A Open file Dialog In ASP 3.0 !!! Pin
HatakeKaKaShi25-Jun-06 15:32
HatakeKaKaShi25-Jun-06 15:32 
QuestionASP to COM HOW TO? Pin
Dave_Roach25-Jun-06 14:41
Dave_Roach25-Jun-06 14:41 
Questionbrowser within an asp.net page Pin
oceanexplorer25-Jun-06 9:33
oceanexplorer25-Jun-06 9:33 
AnswerRe: browser within an asp.net page Pin
swilly126-Jun-06 8:26
swilly126-Jun-06 8:26 
QuestionDot Net Screen Scrapping Error Pin
Dot Net25-Jun-06 8:56
Dot Net25-Jun-06 8:56 
Hi All,
I am trying to get HTML of a page using COMStream. I am running following code.

Imports System
Imports System.Diagnostics
Imports System.Runtime
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.MarshalByRefObject
Imports System.IO
Imports System.ComponentModel
Imports mshtml
Imports SHDocVw

Public Class GetNukeSource
' IPersist interface
<ComVisible(True), ComImport(), Guid("0000010c-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersist
Sub GetClassID(ByRef pClassID As Guid)
End Interface

' IPersistStreamInit interface
<ComVisible(True), ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit : Inherits IPersist
Shadows Sub GetClassID(ByRef pClassID As Guid)
<PreserveSig()> Function IsDirty() As Integer
Sub Load(ByVal pstm As UCOMIStream)
Sub Save(ByVal pstm As UCOMIStream, _
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean)
Sub GetSizeMax(ByRef pcbSize As Long)
Sub InitNew()
End Interface

<DllImport("OLE32.DLL")> _
Private Shared Sub CreateStreamOnHGlobal(ByVal hGlobal As IntPtr, _
ByVal fDelete As Boolean, ByRef stm As UCOMIStream)
End Sub

<DllImport("OLE32.DLL")> _
Public Shared Sub GetHGlobalFromStream(ByVal stm As UCOMIStream, ByRef hGlobal As IntPtr)
' LEAVE THIS BLANK - PLACEHOLDER
End Sub

Dim iptr As IntPtr

Public Function getNukesource(ByVal pageUrl As String) As String
Dim strm As UCOMIStream
Dim ips As IPersistStreamInit
Dim ie As New SHDocVw.InternetExplorer
Dim objDocument As mshtml.IHTMLDocument2
Try
ie.Navigate(pageUrl)

ie.Visible = True

Do Until ie.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
Thread.Sleep(50)
Loop
Catch ex As Exception
Throw ex
Finally
End Try

Dim strRetPage As String
Try
ips = DirectCast(ie.Document, IPersistStreamInit)
Catch ex As Exception
Throw ex
End Try

If ips Is Nothing Then
strRetPage = Nothing
Else
strm = GetStream(2048)
End If

Try
ips.Save(strm, False)

If Not strm Is Nothing Then
strRetPage = Me.StreamToString(strm)
End If
ie.Quit()
Return strRetPage
Catch ex As Exception
Throw ex
End Try

End Function

Private Function GetDocumentSource(ByVal doc As mshtml.IHTMLDocument2, ByVal resetIsDirty As Boolean) As String
Dim stream As UCOMIStream
Dim ips As IPersistStreamInit
Dim s As String
Try
ips = DirectCast(doc, IPersistStreamInit)

If ips Is Nothing Then
s = Nothing
Else
stream = GetStream(2048)

' Save the document into the comstream, without clearing the
ips.Save(stream, False)
s = StreamToString(stream)
End If
Return s
Catch ex As Exception
Throw ex
End Try
End Function

Private Function StreamToString(ByVal strm As UCOMIStream) As String
Dim iptr As IntPtr
Dim s As String
Try
GetHGlobalFromStream(strm, iptr)

' If the source is the cloned and modified document then Auto must be used ***
s = Marshal.PtrToStringAnsi(iptr)
Return s
Catch ex As Exception
Throw ex
End Try
End Function

Private Function GetStream(ByVal size As Integer) As UCOMIStream
Dim iptr As IntPtr
Dim strm As UCOMIStream
Try
' Create a pointer to a block of the required size
iptr = Marshal.AllocHGlobal(size)

' Create the stream from the pointer
CreateStreamOnHGlobal(iptr, True, strm)
Return strm
Catch ex As Exception
Throw ex
End Try
End Function
End Class

This code sometimes runs fine and sometimes gives me following error.

An unhandled exception of type 'System.ExecutionEngineException' occured in translationservice.dll.


Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

After this error comes up CPU usage reaches to 100%.
I do not understand what is the problem with my code. I will appreciate if someone of you guys could help me about it.

Thanks,
Ahmad
Questionhey guys any good videos abt session & application state ? Pin
Mohammed Amine25-Jun-06 7:17
Mohammed Amine25-Jun-06 7:17 
Questioncan we close the application with code ? [modified] Pin
Mohammed Amine25-Jun-06 7:13
Mohammed Amine25-Jun-06 7:13 
Questionhelp me guys to know how to handle a textbox_changed event Pin
Mohammed Amine25-Jun-06 7:10
Mohammed Amine25-Jun-06 7:10 
AnswerRe: help me guys to know how to handle a textbox_changed event Pin
swilly126-Jun-06 8:37
swilly126-Jun-06 8:37 
GeneralRe: help me guys to know how to handle a textbox_changed event [modified] Pin
Mohammed Amine26-Jun-06 10:03
Mohammed Amine26-Jun-06 10:03 
GeneralRe: help me guys to know how to handle a textbox_changed event Pin
Mohammed Amine1-Aug-06 0:32
Mohammed Amine1-Aug-06 0:32 
QuestionHow is Embedding (.swf) in web pages? Pin
coolshad25-Jun-06 6:26
coolshad25-Jun-06 6:26 
GeneralRe: How is Embedding (.swf) in web pages? Pin
Guffa25-Jun-06 9:46
Guffa25-Jun-06 9:46 
AnswerRe: How is Embedding (.swf) in web pages? Pin
Graham Nimbley25-Jun-06 10:01
Graham Nimbley25-Jun-06 10:01 
Questiondatagrid row-nearest row from today Pin
Dhruvil25-Jun-06 5:36
Dhruvil25-Jun-06 5:36 
QuestionGoogle Search Web Service Pin
TheEagle25-Jun-06 4:15
TheEagle25-Jun-06 4:15 
Questionmacromedia flash in asp.net Pin
Hasan Jaffal25-Jun-06 3:55
Hasan Jaffal25-Jun-06 3:55 
AnswerRe: macromedia flash in asp.net Pin
Guffa25-Jun-06 5:12
Guffa25-Jun-06 5:12 
GeneralRe: macromedia flash in asp.net Pin
Hasan Jaffal25-Jun-06 21:30
Hasan Jaffal25-Jun-06 21:30 
QuestionOpening new browser window in a web user control Pin
Mohamed El Gohary25-Jun-06 3:38
Mohamed El Gohary25-Jun-06 3:38 
AnswerRe: Opening new browser window in a web user control Pin
Guffa25-Jun-06 5:12
Guffa25-Jun-06 5:12 
GeneralRe: Opening new browser window in a web user control Pin
Mohamed El Gohary25-Jun-06 21:20
Mohamed El Gohary25-Jun-06 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.