IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

pour q'un textbox lire les codes html


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club  
    Homme Profil pro
    etudiant
    Inscrit en
    Avril 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiant
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 4
    Par défaut pour q'un textbox lire les codes html
    J'ai fais un module pour lire mes mails par POP3 de ma boite hotmail qui marche sans probleme, mais pour les messages que reçoit en HTML je vois tout le code.

    Quelqu'un connaitrait-il un moyen simple d'extraire le texte brut, sans les tags HTML ou un moyen de convertir les code html ?

    mercii


  2. #2
    Membre Expert Avatar de Danyel
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2005
    Messages
    1 699
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 699
    Par défaut
    Comme ca, je dirais sauvegarder/envoyer l'email dans un webbrowser

  3. #3
    Futur Membre du Club  
    Homme Profil pro
    etudiant
    Inscrit en
    Avril 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiant
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 4
    Par défaut
    tu peut me dire comment !!!
    voici le code.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    Imports System
    Imports System.Net.Sockets
    Imports System.Net.Security
    Imports System.Security.Cryptography.X509Certificates
    Imports System.Text
    Imports System.IO
    Imports System.Windows.Forms.WebBrowser
    Imports System.Net
    Imports System.Threading
    Imports System.Windows.Forms
     
     
     
    Public Class Form1 : Inherits System.Windows.Forms.Form
        Dim Server As TcpClient
        Dim NetStrm As System.Net.Security.SslStream
        Dim RdStrm As StreamReader
     
     
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
     
     
     
     
        Private Shared Function CertificateValidationCallback(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors__1 As SslPolicyErrors) As Boolean
            If sslPolicyErrors__1 <> SslPolicyErrors.None Then
                MessageBox.Show("SSL Certificate Validation Error!")
                Debug.Print(sslPolicyErrors__1.ToString())
                Return False
            Else
                Return True
            End If
        End Function
     
        Public Function connect() As Integer
            Dim POP3Account As String
            POP3Account = "pop3.live.com"
            If POP3Account.Trim = "" Then Exit Function
            Try
                Dim certName As String = "pop3.live.com"
                Server = New TcpClient()
                Server.Connect(POP3Account.Trim, 995)
                NetStrm = New SslStream(Server.GetStream(), False, New RemoteCertificateValidationCallback(AddressOf CertificateValidationCallback))
                NetStrm.AuthenticateAsClient(certName)
                RdStrm = New StreamReader(NetStrm)
            Catch exc As Exception
                MsgBox(exc.Message)
                Exit Function
            End Try
     
            Dim user As String
            user = "sts2012@hotmail.fr"
            Dim data As String = "USER " + user.Trim + vbCrLf
            Dim szData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
            NetStrm.Write(szData, 0, szData.Length)
            Dim POPResponse As String
            POPResponse = RdStrm.ReadLine
            If POPResponse.Contains("-ERR") Then
                MsgBox("Invalid user Name")
                Return -1
            End If
            Dim password As String
            password = "sts123"
            data = "PASS " & password & vbCrLf
            szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
            NetStrm.Write(szData, 0, szData.Length)
            POPResponse = RdStrm.ReadLine
            If POPResponse.Contains("-ERR") Then
                MsgBox("Invalid Password")
                Return (-1)
            End If
            data = "STAT" + vbCrLf
            szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
            NetStrm.Write(szData, 0, szData.Length)
            POPResponse = RdStrm.ReadLine
            If POPResponse.Substring(0, 4) = "-ERR" Then
                MsgBox("could not log your in")
                Return -1
            End If
            data = "Stat" + vbCrLf
            szData = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
            NetStrm.Write(szData, 0, szData.Length)
            POPResponse = RdStrm.ReadLine
            If POPResponse.Contains("-ERR") Then
                MsgBox("could not log your in")
                Return -1
            End If
            Dim parts() As String
            parts = POPResponse.Split(" ")
            Dim messages As Integer
     
            'messages = parts(3)
            messages = CInt(parts(1))
            Return messages
     
        End Function
        Public Function DeleteMessage(ByVal msgIndex As Integer)
            Dim data As String = "DELE " & msgIndex.ToString & vbCrLf
            Dim SzData() As Byte = System.Text.Encoding.ASCII.GetBytes(data.ToCharArray())
            NetStrm.Write(SzData, 0, SzData.Length)
            Dim tmpString As String = RdStrm.ReadLine()
            If tmpString.Substring(0, 4) = "-ERR" Then
                MsgBox("Could Not Delete Message")
                Return (-1)
            Else
                Return 11
            End If
        End Function
     
     
     
        Public Structure Message
            Dim _From As String
            Dim _To As String
            Dim _Date As String
            Dim _Subject As String
            Dim _CC As String
            Dim _BCC As String
            Dim _Body As String
            Dim _Received As String
        End Structure
     
        Public Function CreateFromText(ByVal strMessage As String) As Message
            Dim Mssg As New Message
            Dim brkPos As Integer
            Dim Header As String
            Dim Headers() As String
            Dim Body As String
            Dim HeaderName As String
            Dim HeaderValue As String
            brkPos = InStr(1, strMessage, vbCrLf & vbCrLf)
            If brkPos Then
                Header = strMessage.Substring(0, brkPos - 1)
                Body = strMessage.Substring(brkPos + 1, _
                strMessage.Length - Header.Length - 3)
                Mssg._Body = Body
            Else
                Throw New Exception("Invalid Message Format")
                Exit Function
            End If
            Headers = Split(Header, vbCrLf)
            Dim _header As String
            For Each _header In Headers
                brkPos = _header.IndexOf(":")
                If brkPos >= 0 Then
                    HeaderName = _header.Substring(0, brkPos)
                Else
                    HeaderName = ""
                End If
                HeaderValue = _header.Substring(brkPos + 1)
                Select Case HeaderName.ToLower
                    Case "received"
                        Mssg._Received = HeaderValue
                    Case "from"
                        Mssg._From = HeaderValue
                    Case "to"
                        Mssg._To = HeaderValue
                    Case "cc"
                        Mssg._CC = HeaderValue
                    Case "bcc"
                        Mssg._BCC = HeaderValue
                    Case "subject"
                        Mssg._Subject = HeaderValue
                    Case "date"
                        Mssg._Date = HeaderValue
                End Select
            Next
            Return Mssg
        End Function
        Function GetMessage(ByVal msgindex As Integer) As String
            Dim tmpString As String
            Dim Data As String
            Dim SzData() As Byte
            Dim msg As String
     
            Try
                Data = "RETR " & msgindex.ToString & vbCrLf
                SzData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
                NetStrm.Write(SzData, 0, SzData.Length)
                tmpString = RdStrm.ReadLine()
                If tmpString.Substring(0, 4) <> "-ERR" Then
                    While (tmpString <> ".")
                        msg = msg & tmpString & vbCrLf
                        tmpString = RdStrm.ReadLine
                    End While
                End If
            Catch exc As InvalidOperationException
                MsgBox("Message Retrival Failed: " & vbCrLf & Err.ToString())
            End Try
            Return msg
        End Function
     
        Private Sub btnMailReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMailReceive.Click
            Dim i As Integer
            Dim msg As Form1.Message
            Dim msgstring As String
            Dim messages1 As Integer
            Me.Cursor = Cursors.WaitCursor
            messages1 = connect()
            If messages1 = -1 Then
                Me.Cursor = Cursors.Default
                Exit Sub
            End If
            Dim originalCaption As String = Me.Text
            For i = 1 To messages1
                Me.Text = "Downloading Message " & i.ToString & "/" & _
                messages1.ToString
                Dim msgitem As New ListViewItem
                msgstring = GetMessage(i)
                msg = CreateFromText(msgstring)
                msgitem.Text = msg._From
                msgitem.SubItems.Add(msg._Subject)
                msgitem.SubItems.Add(msg._Date)
                lstMailList.Items.Add(msgitem)
                txtMailContent.AppendText(msg._Body & vbCrLf)
            Next
            Me.Text = originalCaption
            Me.Cursor = Cursors.Default
        End Sub
     
        Private Sub lstMailList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
     
            'Dim objPOP3 As POP3Message
            txtMailContent.Text = GetMessage(lstMailList.SelectedIndices(0) + 1)
        End Sub
     
        Private Sub lstMailList_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstMailList.KeyUp
            If e.KeyCode = Keys.Delete Then
                If DeleteMessage(lstMailList.SelectedIndices(0) + 1) >= 0 Then
                    lstMailList.Items(lstMailList.SelectedIndices(0)).Text = "DELETED"
                    lstMailList.Items(lstMailList.SelectedIndices(0)).SubItems.Clear()
                    MsgBox("Your Email Message is Deleted", MsgBoxStyle.Information, "Delete Message")
                End If
            End If
        End Sub
     
        Private Sub btnQUIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQUIT.Click
     
        End Sub
     
        Private Sub lstMailList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMailList.SelectedIndexChanged
     
        End Sub
     
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        End Sub
     
        Private Sub txtMailContent_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMailContent.TextChanged
     
        End Sub
     
        Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
     
        End Sub
    End Class

  4. #4
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2006
    Messages
    128
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2006
    Messages : 128
    Par défaut
    t'as

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Server.HtmlEncode(textbox.text)
    ça fera l'affaire normalement

  5. #5
    Futur Membre du Club  
    Homme Profil pro
    etudiant
    Inscrit en
    Avril 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : etudiant
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 4
    Par défaut
    ca marche pas tjr :-( :-( :-(

Discussions similaires

  1. Macro pour lire les codes d'une base
    Par étudiant11 dans le forum Macro
    Réponses: 6
    Dernier message: 18/03/2015, 15h28
  2. API pour lire les codes barres
    Par rwikus09 dans le forum API standards et tierces
    Réponses: 15
    Dernier message: 06/04/2011, 10h53
  3. Convertir les codes HTML en équivalent pour JavaScript
    Par bubulemaster dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 20/08/2009, 11h20
  4. Lire les fichiers html
    Par ERICKO dans le forum Fortran
    Réponses: 5
    Dernier message: 24/02/2007, 02h44
  5. [RegEx] motif pour remplacer un mot dans du code HTML ...
    Par r-zo dans le forum Langage
    Réponses: 6
    Dernier message: 31/03/2006, 13h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo