Site Search:
Sign in | Join | Help
4Penny.net

ASP.NET

Notes, Tricks and Tips on ASP.NET Coding

January 2007 - Posts

  • Formatting for Datagrid template column fields

    If you need to format a datagrid template column fields, it can be hard to find the documentation.

    Text='<%# DataBinder.Eval(Container.DataItem, "qtyRemaining", "{0:F0}")%>'

    will make the column format as floating point, zero decimal places.

  • Authenticate mail in VB.NET 2.0

    Here's a piece of code that I use all the time. I've added code now for multiple CCs and an attachment 

    Public Sub sendMail(ByVal strBody As String, ByVal strSubject As String, ByVal strFilename As String)
    
    
        Try
            Dim strServer As String = System.Configuration.ConfigurationManager.AppSettings("emailserver")
            Dim strUser As String = System.Configuration.ConfigurationManager.AppSettings("emailuser")
            Dim strPassword As String = System.Configuration.ConfigurationManager.AppSettings("emailpassword")
            Dim strTo As String = System.Configuration.ConfigurationManager.AppSettings("emailTo")
            Dim strCC As String = System.Configuration.ConfigurationManager.AppSettings("emailCC")
            Dim strCCArray() As String = strCC.Split(";")
    
    
            Dim mail As New System.Net.Mail.MailMessage(strUser, strTo)
    
    
            For Each cc In strCCArray
                mail.CC.Add(cc)
            Next
    
    
            mail.Subject = strSubject
            mail.Body = strBody
            mail.IsBodyHtml = True
    
    
            mail.Priority = Net.Mail.MailPriority.Normal
    
    
            Dim att As New Net.Mail.Attachment(strFilename, "image/x-portable-bitmap")
            mail.Attachments.Add(att)
    
    
            Dim serv As New System.Net.Mail.SmtpClient(strServer)
    
    
            If strUser > "" And strPassword > "" Then
                serv.Credentials = New System.Net.NetworkCredential(strUser, strPassword)
            End If
    
    
            'serv.UseDefaultCredentials = False
            'serv.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
    
    
            serv.Send(mail)
    
    
    
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    
    
    
    End Sub
    
    
    
    End Sub

    Here's the app.config code:

    <appSettings>
     <add key="emailserver" value="mymailserver"/>
     <add key="emailuser" value=""/>
     <add key="emailpassword" value=""/>
     <add key="emailTo" value=""/>
     <add key="emailCC" value=<a href="mailto:me@nowhere.com;me@somewhere.com">me@nowhere.com;me@somewhere.com</a>/>
    </appSettings>
    
    
    
     
     

     

     

  • ASPDOTNETSTOREFRONT mail setup

    To get ASPDOTNETSTOREFRONT mail to work, set the following fields

    MailMe_User
    MailMe_Pwd
    MailMe_Server
    MailMe_ToAddress
More Posts Next page »