Pls Correct my code !

  • 13 years ago

    Hey Pls correct this code below as you can

    Public Sub ConvertImagesToEmbeddedMailImages(ByVal html As String, ByRef emailMessage As CDO.Message)

    Dim document As HtmlDocument = HtmlDocument.Create(html, False)

    Dim imageNodes As New HtmlNodeCollection()

    ' Get All the img nodes

    GetImageNodes(document.Nodes, imageNodes)

    For Each element As HtmlElement In imageNodes

    Dim path As String = HttpContext.Current.Server.MapPath(element.Attributes("src").Value)

    Dim imageFileInfo As New FileInfo(HttpContext.Current.Server.MapPath(element.Attributes("src").Value))

    Dim contentId As String = imageFileInfo.Name.Replace(imageFileInfo.Extension, String.Empty)

    Dim bodyPart As CDO.IBodyPart = emailMessage.AddRelatedBodyPart(path, contentId, CDO.CdoReferenceType.cdoRefTypeLocation, String.Empty, String.Empty)bodyPart.Fields.Append("urn:schemas:mailheader:Content-ID", DataTypeEnum.adVariant, 255, FieldAttributeEnum.adFldMayBeNull, String.Format("<{0}>", contentId))


    'Change the src to "cid:<contentId>"

    element.Attributes("src").Value = String.Format("cid:{0}", contentId)


    ' set the email text to the modified html

    emailMessage.HTMLBody = document.HTML

    End Sub

    Private Sub GetImageNodes(ByVal nodes As HtmlNodeCollection, ByRef imageNodes As MIL.Html.HtmlNodeCollection)

    For Each node As HtmlNode In nodes

    Dim element As HtmlElement = TryCast(node, HtmlElement)

    If element IsNot Nothing Then

    If element.Name.ToLower() = "img" Then


    End If

    If element.Nodes.Count > 0 Then

    GetImageNodes(element.Nodes, imageNodes)

    End If

    End If


    End Sub

    I need in urgent na.

    regard from

    spider anatha


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond