Sending Mail using SmtpClient

October 29, 2007 at 9:37 am | In Dot Net | Leave a Comment

Imports System.Net.Mail

Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim smtpClient As New SmtpClient
Dim message As New MailMessage

Dim fromAddress As New MailAddress(host site mail address)
Dim toAddress As New MailAddress(receiver mail address)
Try
‘You can specify the host name or ipaddress of your server
‘ Default in IIS will be localhost
smtpClient.Host = “localhost”

‘Default port will be 25
smtpClient.Port = 25

‘From address will be given as a MailAddress Object
message.From = fromAddress

‘To address collection of MailAddress
message.To.Add(toAddress)
message.Subject = “Feedback”

‘// CC and BCC optional
‘// MailAddressCollection class is used to send the email to various users
‘// You can specify Address as new MailAddress(“admin1@yoursite.com”)
message.CC.Add(“admin1@yoursite.com”);
message.CC.Add(“admin2@yoursite.com”);

‘// You can specify Address directly as string
message.Bcc.Add(new MailAddress(“admin3@yoursite.com”));
message.Bcc.Add(new MailAddress(“admin4@yoursite.com”));

‘Body can be Html or text format
‘Specify true if it is html message
message.IsBodyHtml = False

‘Message body content
message.Body = [message as string]

‘Send SMTP mail
smtpClient.Send(message)

Response.Write(“alert(‘Email successfully
sent.’);”)
Catch ex As Exception
Response.Write(“alert(‘Email sent fail.’);”)
End Try
End Sub

Use File Upload control with read only text box.

October 24, 2007 at 12:44 pm | In Dot Net | 1 Comment

Query :
File Upload Control read only so that no one can
edit file upload text box.
User can select files only with Browse button.

Solution :
Use javascript for this purpose

<input id=”File1″ type=”file” onkeypress=”javascript: return false;” />
 

Calling Crystal report viewer in dot net

October 23, 2007 at 12:57 pm | In Dot Net | Leave a Comment

Using Crystal report in dot net

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Dim intCounter As Integer
Dim intCounter1 As Integer

‘Crystal Report’s report document object
Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

‘object of table Log on info of Crystal report
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo

‘Sub report object of crystal report.
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject

‘Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim index As Integer

‘Load the report
objReport.Load()

‘Set the connection information
ConInfo.ConnectionInfo.UserID =
ConInfo.ConnectionInfo.Password =
ConInfo.ConnectionInfo.ServerName =
ConInfo.ConnectionInfo.DatabaseName =

For intCounter = 0 To objReport.Database.Tables.Count – 1
objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next

‘ Loop through each section on the report then look
‘ through each object in the section
‘ if the object is a subreport, then apply logon info
‘ on each table of that sub report

For index = 0 to objReport.ReportDefinition.Sections.Count – 1
For intCounter = 0 To _
objReport.ReportDefinition.Sections(index).ReportObjects.Count – 1
With objReport.ReportDefinition.Sections(index)
If .ReportObjects(intCounter).Kind = _
CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(intCounter), _
CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = _
mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count – 1
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo( _
ConInfo)
Next
End If
End With
Next
Next

‘If there is a selection formula
If sSelectionFormula.Length > 0 Then
objReport.RecordSelectionFormula = sSelectionFormula
End If

‘Formula fields in string with key-value pair.
‘Key-value separated by comma and forumlas are seperated by |
If sFormulas.Trim() “” Then
Dim sFormulaWithValues() As String = Split(sFormulas, “|”)
Dim i As Integer
For i = 0 To UBound(sFormulaWithValues)
Dim sFormulaValue() As String = Split(sFormulaWithValues(i), “,”)
objReport.DataDefinition.FormulaFields(sFormulaValue(0)).Text = sFormulaValue(1)
Next i
End If

‘Report file name
sFileName = AppDomain.CurrentDomain.BaseDirectory & “reports\” & sFileName

CrystalReportViewer1.ReportSource = objReport
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.DataBind()
‘Toolbar
CrystalReportViewer1.DisplayToolbar = True
‘Group tree
CrystalReportViewer1.DisplayGroupTree = False

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.