Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
2012 gives warnings
Message
From
18/09/2012 00:17:52
 
General information
Forum:
ASP.NET
Category:
Visual Studio
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01553080
Message ID:
01553107
Views:
54
>Make sure the target of your main project is set to x86 and not 'All Processors'. ADODB Interop requires 32 bit operation so if you compile with neutral it will potentially run in 64 bit and break - the compiler is letting you know that this is a problem.

It does in deed resolve the issue. Thanks

>Why are you using ADODB and CDO? These have much better replacements in .NET.

Those two are used in my MHTML class. If you want, you may take a look here and see if you can find a way to avoid those two and use something more recent:
Imports CDO
Imports ADODB

Namespace Framework

    Public Class MHTML

        Public cCookie As String = ""
        Public cLoginUrl As String = ""
        Public cMHTMLUrl As String = ""
        Public cPassword As String = ""
        Public cSaveFile As String = ""
        Public cUsername As String = ""
        Public oApp As Framework.App

        ' Collection to hold the form fields to be used when there is a login page
        Private oFormField As Collection = New Collection

        ' CDO message object
        Private oMessage As CDO.Message = New CDO.Message

        Private oProcess As Framework.LXProcess

        ' This is when we access the class in a desktop mode
        Sub New(ByVal toApplication As Framework.App)
            oApp = toApplication
        End Sub

        ' This is when we access the class in a Web or Web Service mode
        Public Sub New(ByVal toProcess As Framework.LXProcess)
            oProcess = toProcess
            oApp = oProcess.oApp
        End Sub

        ' Do the login
        Private Function Login() As Boolean
            Dim lcCookie As String = ""
            Dim lcPostData As String = ""
            Dim llSuccess As Boolean = False
            Dim lnCounter As Integer = 0
            Dim loASCIIEncoding As System.Text.Encoding = New System.Text.ASCIIEncoding
            Dim loByte() As Byte
            Dim loCookieCollection As System.Net.CookieCollection
            Dim loCookieContainer As System.Net.CookieContainer = New System.Net.CookieContainer
            Dim loFormField(2) As Object
            Dim loStreamWebRequest As IO.Stream
            Dim loWebRequest As System.Net.HttpWebRequest
            Dim loWebResponse As System.Net.HttpWebResponse

            ' Get the post data
            For Each loFormField In oFormField

                ' If we have a post
                If lcPostData.Length > 0 Then
                    lcPostData = lcPostData + "&"
                End If

                lcPostData = lcPostData + loFormField(1) + "=" + loFormField(2)
            Next

            loByte = loASCIIEncoding.GetBytes(lcPostData)

            ' Prepare Web request
            loWebRequest = System.Net.WebRequest.Create(cLoginUrl)
            loWebRequest.Method = "POST"
            loWebRequest.ContentType = "application/x-www-form-urlencoded"
            loWebRequest.ContentLength = lcPostData.Length

            ' Send the data
            loStreamWebRequest = loWebRequest.GetRequestStream()
            loStreamWebRequest.Write(loByte, 0, loByte.Length)
            loStreamWebRequest.Close()

            loWebRequest.CookieContainer = New System.Net.CookieContainer()

            ' Get the cookie
            loWebResponse = loWebRequest.GetResponse()
            loCookieCollection = loWebRequest.CookieContainer.GetCookies(loWebRequest.RequestUri)

            ' For each cookie in the collection
            For lnCounter = 0 To loCookieCollection.Count - 1
                lcCookie = loCookieCollection.Item(lnCounter).Name

                ' If this is the cookie
                If lcCookie = cCookie Then
                    lcCookie = loCookieCollection.Item(lnCounter).Value

                    ' Define the cookie
                    oMessage.Configuration.Fields.Item(CDO.CdoConfiguration.cdoHTTPCookies).Value = _
                     cCookie + "=" + lcCookie

                    oMessage.Configuration.Fields.Update()
                    Exit For
                End If

            Next

            llSuccess = True

            Return llSuccess
        End Function

        ' Get the MHTML file
        Public Function GetMHTML() As Boolean
            Dim llSuccess As Boolean = False
            Dim loStream As ADODB.Stream

            ' If we have something in the collectin
            If oFormField.Count > 0 Then

                ' Do the login
                If Not Login() Then
                    Return False
                End If

            End If

            ' Go get the page
            oMessage.CreateMHTMLBody(cMHTMLUrl, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")

            loStream = oMessage.GetStream()

            ' Save to file
            loStream.SaveToFile(cSaveFile, SaveOptionsEnum.adSaveCreateOverWrite)

            llSuccess = True

            Return llSuccess
        End Function

        ' Add a form field for the post that can be used to do the login
        ' expC1 Name
        ' expC2 Value
        Public Function AddFormField(ByVal tcName As String, ByVal tcValue As String) As Boolean
            Dim loFormField(2) As Object

            loFormField(1) = tcName
            loFormField(2) = tcValue

            oFormField.Add(loFormField)

            Return True
        End Function

    End Class

End Namespace
In the GetMHTML() method, you can see I need those two. I do not know if there is someting simpler than that.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform