Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
DownloadPage.aspx

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If Session("Branch") = 1 Then
Response.Redirect("~/SamplePage1.aspx", False)
HttpContext.Current.ApplicationInstance.CompleteRequest()
ElseIf Session("Branch") = 2 Then
Response.Redirect("~/SamplePage2.aspx", False)
HttpContext.Current.ApplicationInstance.CompleteRequest()
End If
Catch ex As Exception
Session("Error Message") = ex.Message
Response.Redirect("~/ErrorPage.aspx")
End Try
End Sub

PrintPage.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("user") <> s Then
temp = Session("user").ToString()
End If
Dim strQuery As String = "select * from tblAccount_Reservation where" _
& " fldID = @fldID"
con.Open()

Using cmd As New SqlCommand()
cmd.Parameters.AddWithValue("@fldID", Session("user"))
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con


Dim sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Labelemail.Text = sdr("fldEmail").ToString()
Labelfirst.Text = sdr("fldfirstname").ToString()
End While
sdr.Close()
cmd.ExecuteNonQuery()
End Using

If Not IsPostBack Then

GrabData(Session("user"))

End If


End Sub

Private Sub GrabData(ByVal ID As String)
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing

ServicePointManager.ServerCertificateValidationCallback = _
New System.Net.Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)

Me.Report1.LocalReport.DataSources.Clear()
Dim adapter As New AupairTempRegistration1TableAdapters.tblaupairtempTableAdapter()
Dim table As New AupairTempRegistration1.tblaupairtempDataTable
adapter.FillByID(table, ID)

Me.Report1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", CType(table, DataTable)))
Report1.LocalReport.ReportPath = "Reports/Report4.rdlc"
Report1.LocalReport.EnableExternalImages = True
Me.Report1.DataBind()

Dim bytes As Byte() = Report1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, _
warnings)

Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", ("attachment; filename=" & "Personal Data and Barcoded Information Form" & ".") + extension)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.BinaryWrite(bytes)

Dim memorystream As New MemoryStream
memorystream.Seek(0, SeekOrigin.Begin)
Dim message As New MailMessage
Dim Attached As New Attachment(memorystream, "Report4.pdf")
message.Attachments.Add(New Attachment(New MemoryStream(bytes), "Barcoded_Confirmation_Form_" & DateTime.Now.ToString("MM.dd.yy") & ".pdf"))



message.From = New MailAddress("blankman@yahoo.com")
message.To.Add(Labelemail.Text)
message.CC.Add(Labelemail.Text)

message.Subject = "Personal Data Form and Barcoded Information"
message.IsBodyHtml = True

message.Body = "Good Day!" + " " + Labelfirst.Text + " " + "Please see the Attachment."

Dim mail_client As SmtpClient = New SmtpClient()
Dim str_from_address As String = "evpappointment@cfo.gov.ph"

'//Providing Credentials (Username & password)
Dim network_cdr As NetworkCredential = New NetworkCredential()
network_cdr.UserName = str_from_address
network_cdr.Password = "e05v22p16"

mail_client.Host = "mail.cfo.gov.ph" '; //SMTP host
mail_client.UseDefaultCredentials = False
mail_client.Credentials = network_cdr
'//End

mail_client.Send(message)

End Sub

What I have tried:

PrintPage.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("user") <> s Then
temp = Session("user").ToString()
End If
Dim strQuery As String = "select * from tblAccount_Reservation where" _
& " fldID = @fldID"
con.Open()

Using cmd As New SqlCommand()
cmd.Parameters.AddWithValue("@fldID", Session("user"))
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con


Dim sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Labelemail.Text = sdr("fldEmail").ToString()
Labelfirst.Text = sdr("fldfirstname").ToString()
End While
sdr.Close()
cmd.ExecuteNonQuery()
End Using

If Not IsPostBack Then

GrabData(Session("user"))

End If


End Sub

Private Sub GrabData(ByVal ID As String)
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing

ServicePointManager.ServerCertificateValidationCallback = _
New System.Net.Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)

Me.Report1.LocalReport.DataSources.Clear()
Dim adapter As New AupairTempRegistration1TableAdapters.tblaupairtempTableAdapter()
Dim table As New AupairTempRegistration1.tblaupairtempDataTable
adapter.FillByID(table, ID)

Me.Report1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", CType(table, DataTable)))
Report1.LocalReport.ReportPath = "Reports/Report4.rdlc"
Report1.LocalReport.EnableExternalImages = True
Me.Report1.DataBind()

Dim bytes As Byte() = Report1.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, _
warnings)

Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", ("attachment; filename=" & "Personal Data and Barcoded Information Form" & ".") + extension)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.BinaryWrite(bytes)

Dim memorystream As New MemoryStream
memorystream.Seek(0, SeekOrigin.Begin)
Dim message As New MailMessage
Dim Attached As New Attachment(memorystream, "Report4.pdf")
message.Attachments.Add(New Attachment(New MemoryStream(bytes), "Barcoded_Confirmation_Form_" & DateTime.Now.ToString("MM.dd.yy") & ".pdf"))



message.From = New MailAddress("blankman@yahoo.com")
message.To.Add(Labelemail.Text)
message.CC.Add(Labelemail.Text)

message.Subject = "Personal Data Form and Barcoded Information"
message.IsBodyHtml = True

message.Body = "Good Day!" + " " + Labelfirst.Text + " " + "Please see the Attachment."

Dim mail_client As SmtpClient = New SmtpClient()
Dim str_from_address As String = "evpappointment@cfo.gov.ph"

'//Providing Credentials (Username & password)
Dim network_cdr As NetworkCredential = New NetworkCredential()
network_cdr.UserName = str_from_address
network_cdr.Password = "e05v22p16"

mail_client.Host = "mail.cfo.gov.ph" '; //SMTP host
mail_client.UseDefaultCredentials = False
mail_client.Credentials = network_cdr
'//End

mail_client.Send(message)

End Sub
Please help me
Posted
Updated 5-Dec-17 6:54am

1 solution

Hi Lorenzo,

When you say "localhost", do you mean your development machine? assuming you published your site to another computer(server), did you installed the appropriate Report Viewer Runtime redistributable package on that other machine?

Remember, the runtime package must be the right one for your ReportViewer version; e.g. 2008, 2010, 2012, etc.

Cheers!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900