<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7116253520371246712</id><updated>2012-02-16T11:28:01.555-08:00</updated><category term='Storing and retrieving Crystal reports in Database'/><category term='Insert crystal report in database'/><title type='text'>Tech Touch</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7116253520371246712.post-4833152330912627329</id><published>2009-08-05T06:10:00.000-07:00</published><updated>2009-08-05T06:36:13.959-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Insert crystal report in database'/><category scheme='http://www.blogger.com/atom/ns#' term='Storing and retrieving Crystal reports in Database'/><title type='text'>Storing and retrieving Crystal reports in Database</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Storing and retrieving Crystal reports in Database&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;         It is not advisable to store and retrieve the crystal reports in database due to increase the system as well the network performance.  The right way is store the reports in local disk and file name in database. Even though a lot of ways to secure the files in system disk, some clients not compromise with that.&lt;br /&gt;   So in this thread I’m representing a way to store the crystal reports in database and a way to retrieve it and show to the user&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-weight: bold;"&gt;Create and Store Report in Database:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;·    Create a layout file (rpt). You can use either PULL or PUSH method to create the report.&lt;br /&gt;·    Add a ReportDocument object and do the necessary steps to load the report into that Report Document object (Load report, set required parameters, set Login information in the case of PULL method and set SetDatasource in the case of PUSH method). There are many articles related to this, so I’m not going to discuss this in depth.&lt;br /&gt;·    Create a table with a column VARBINARY(MAX) to store the binary format of report.&lt;br /&gt;·    Write the below procedure to insert the value in to the table. Here you can use your inline query instead of stored procedure also.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;CREATE PROCEDURE [dbo].[USP_INSERT_REPORT_INDB]&lt;br /&gt; @report_id                AS INT  &lt;br /&gt;,@report_image                AS VARBINARY(MAX)&lt;br /&gt;,@report_creator                  AS INT&lt;br /&gt;AS    &lt;br /&gt;BEGIN&lt;br /&gt;    INSERT INTO [dbo].[REPORT_DETAIL]([report_id,[rd_image],[rd_created_date],[rd_creator])&lt;br /&gt;    VALUES(@report_id,@report_image,GETDATE(),@report_creator)&lt;br /&gt;END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;·    Write the below C# code to convert the report document object into binary and store it in database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;private bool SaveReportInDB(ReportDocument crReportDocument)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;bool IsReportSavedInDB = false;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;int reportId = Convert.ToInt32(ViewState["reportId"]);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;int reportCreator;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//If you are going to show rpt file next time from DB use ExportFormatType.CrystalReport Or use the appropriate type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;MemoryStream memStream = MemoryStream)crReportDocument.ExportToStream(ExportFormatType.CrystalReport);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;string connection_string = "your connecion string";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlConnection myConnection = new SqlConnection(connection_string);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;myConnection.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlCommand myCommand = new SqlCommand("USP_INSERT_REPORT_INDB", myConnection);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;myCommand.CommandType = CommandType.StoredProcedure;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;SqlParameter pramReportId = new SqlParameter("@report_id", reportId);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlParameter paramReport = new SqlParameter("@report_image", memStream.ToArray());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlParameter paramReportCreator = new SqlParameter("@report_creator", reportCreator);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;// add the parameter to the Command's Parameters collection&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;myCommand.Parameters.Add(pramReportId);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;myCommand.Parameters.Add(paramReport);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;myCommand.Parameters.Add(paramReportCreator);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Call the SP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;myCommand.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;IsReportSavedInDB = true;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;catch (Exception)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;return IsReportSavedInDB;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Retrieve and display Report from Database&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;·    Same like above write a inline query or SP to retive the stored report data&lt;br /&gt;·    Write the below code in your C#&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;private void LoadReport()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;ReportDocument crReportDocument = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;string filename = string.Empty;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Create a new SQL Connection to the database&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlConnection sqlCon = new &lt;/span&gt;&lt;span style="font-family:arial;"&gt;SqlConnection("Server=server;Database=db;uid=uis;pwd=pass");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Create a command object for reading document from Database&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlCommand sqlCom = new SqlCommand(&lt;/span&gt;&lt;span style="font-family:arial;"&gt;"Select rd_image from REPORT_DETAIL Where report_id=1", sqlCon);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;sqlCon.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Read data into DataReader&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SqlDataReader sqlDr = sqlCom.ExecuteReader();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;while (sqlDr.Read())&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;span style="font-family:arial;"&gt;&lt;br /&gt;//If you store the report in rpt format then the extension should be in .rpt or in appropriate format&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;filename = Server.MapPath("report_archive") + "\\testReportDB.rpt";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Read binary Data into Bytes Array&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;byte[] fileBytes = (byte[])sqlDr["rd_image"];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Create FileStream Object from for saving file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;FileStream oFileStream = new FileStream(filename, FileMode.Create);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//SaveFile&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;oFileStream.Write(fileBytes, 0, fileBytes.Length);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Dispose the memory of used objects&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;oFileStream.Close(); oFileStream.Dispose();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;fileBytes = null;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;//Close Reader and Connection&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;sqlDr.Close(); sqlCon.Close();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;//Dispose Memory&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;sqlDr.Dispose(); sqlCon.Dispose(); sqlCom.Dispose();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;//if yo want to load the report in crystal report viewer use the below code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;// Or if you want render directly just open the 'filename' in new browser(in case pdf,doc and excel files)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;if (filename != string.Empty)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;crReportDocument = new ReportDocument();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;crReportDocument.Load(filename);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:arial;"&gt;CrystalReportViewer1.ReportSource = crReportDocument;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;catch (Exception ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Response.Write(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here the main problem may be the removing of temporary created files. I will come with the update for that.&lt;br /&gt;Any comments and feedbacks always welcome…..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7116253520371246712-4833152330912627329?l=natrajt.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/4833152330912627329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7116253520371246712&amp;postID=4833152330912627329' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/4833152330912627329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/4833152330912627329'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/2009/08/storing-and-retrieving-crystal-reports.html' title='Storing and retrieving Crystal reports in Database'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7116253520371246712.post-5251646177576539229</id><published>2008-09-29T01:32:00.000-07:00</published><updated>2008-09-29T04:49:55.231-07:00</updated><title type='text'>genral tips</title><content type='html'>genral tips&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7116253520371246712-5251646177576539229?l=natrajt.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/5251646177576539229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7116253520371246712&amp;postID=5251646177576539229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/5251646177576539229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/5251646177576539229'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/2008/09/using-code-1.html' title='genral tips'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7116253520371246712.post-5018575191576631298</id><published>2008-06-16T12:30:00.000-07:00</published><updated>2008-09-25T22:34:33.055-07:00</updated><title type='text'>Dynamic Images at runtime in Crystal Report XI using ASP.Net 2.0</title><content type='html'>&lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;Hello,&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;u1:p&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;This article helps to display dynamic Images in crystal report Using ASP.Net 2.0.&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt; We can use two methods to dynamically change the picture in the crystal report&lt;u1:p&gt; either the Image stored in the database as a BLOB and as a picture &lt;/u1:p&gt;available in the local path.&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style=""&gt;&lt;br /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;Method I: Using recordset&lt;/span&gt;&lt;/b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;u1:p&gt; &lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;   1. Add a recordset and add a table in that. Add a column of&lt;span style="color:maroon;"&gt; System.Byte[] &lt;/span&gt;(Only&lt;span style="color:maroon;"&gt; System.Byte &lt;/span&gt;is available in the data type of data Table, Manually add the&lt;span style="color:maroon;"&gt; System.Byte[] &lt;/span&gt;in that. &lt;span style="color:maroon;"&gt;System.Byte &lt;/span&gt;not allowed for images).Then use the below code &lt;u2:p&gt;&lt;/u2:p&gt;&lt;/span&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;   2. Design the report with that dataset. You can add this&lt;span style="color:maroon;"&gt; System.Byte[] &lt;/span&gt;column as part of your main data table which have the all data or add a separate data table with a&lt;span style="color:maroon;"&gt; System.Byte[] &lt;/span&gt;and a key column that link to the main data table.&lt;u2:p&gt;&lt;/u2:p&gt;&lt;/span&gt;&lt;u3:p&gt;&lt;/u3:p&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:maroon;"   &gt;   3. Add the below code    &lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:blue;"   &gt;        private&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt; &lt;span style="color:teal;"&gt;ds_Images&lt;/span&gt; Images1;&lt;br /&gt;      &lt;span style="color:teal;"&gt;rptTest&lt;/span&gt; crReportDocument = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;rptTest&lt;/span&gt;();  // &lt;span style="color:teal;"&gt;rptTest is your crystal report name&lt;/span&gt;&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;    &lt;span style="color:blue;"&gt;protected&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; btnShowReport_Click(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color:teal;"&gt;EventArgs&lt;/span&gt; e)&lt;br /&gt;      {&lt;u1:p&gt;&lt;/u1:p&gt;&lt;br /&gt;          ImageTable();               crReportDocument.Database.Tables[&lt;span style="color:maroon;"&gt;"tblImages"&lt;/span&gt;].SetDataSource(Images1.Tables[0].DataSet);&lt;br /&gt;          &lt;span style="color:blue;"&gt;string&lt;/span&gt; ExportPathFinal;&lt;br /&gt;          ExportPathFinal = ExportPath + &lt;span style="color:maroon;"&gt;"\\"&lt;/span&gt; + &lt;span style="color:maroon;"&gt;"TEMP"&lt;/span&gt; + &lt;span style="color:maroon;"&gt;"\\"&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:teal;"&gt;Directory&lt;/span&gt;.Exists(ExportPathFinal) == &lt;span style="color:blue;"&gt;false&lt;/span&gt;) &lt;span style="color:teal;"&gt;Directory&lt;/span&gt;.CreateDirectory(ExportPathFinal);&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            //Export &lt;st1:city st="on"&gt;&lt;st1:place st="on"&gt;&lt;st1:city st="on"&gt;&lt;st1:place st="on"&gt;Crystal&lt;/st1:place&gt;&lt;/st1:city&gt;&lt;/st1:place&gt;&lt;/st1:city&gt; Report to PDF &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            &lt;span style="color:teal;"&gt;ExportOptions&lt;/span&gt; crExportOptions = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;ExportOptions&lt;/span&gt;();&lt;br /&gt;          &lt;span style="color:teal;"&gt;DiskFileDestinationOptions&lt;/span&gt; crDiskFileDestinationOptions = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;DiskFileDestinationOptions&lt;/span&gt;();&lt;br /&gt;          crExportOptions = crReportDocument.ExportOptions;&lt;br /&gt;          crDiskFileDestinationOptions.DiskFileName = ExportPathFinal + &lt;span style="color:maroon;"&gt;"MyreportTest.pdf"&lt;/span&gt;;&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            //Set the required report ExportOptions properties&lt;br /&gt;          crExportOptions.ExportDestinationType = &lt;span style="color:teal;"&gt;ExportDestinationType&lt;/span&gt;.DiskFile;&lt;br /&gt;          crExportOptions.ExportFormatType = &lt;span style="color:teal;"&gt;ExportFormatType&lt;/span&gt;.PortableDocFormat; // Or any other Format&lt;br /&gt;          crExportOptions.DestinationOptions = crDiskFileDestinationOptions;&lt;br /&gt;          crReportDocument.Export();        &lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            &lt;span style="color:blue;"&gt;string&lt;/span&gt; ExportPathFinal1 = ExportPath1 + &lt;span style="color:maroon;"&gt;"\\"&lt;/span&gt; + &lt;span style="color:maroon;"&gt;"TEMP"&lt;/span&gt; + &lt;span style="color:maroon;"&gt;"\\"&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color:blue;"&gt;string&lt;/span&gt; pathToPDFfile = ExportPathFinal1 + &lt;span style="color:maroon;"&gt;"MyreportTest.pdf"&lt;/span&gt;;&lt;br /&gt;          Response.Redirect(pathToPDFfile, &lt;span style="color:blue;"&gt;true&lt;/span&gt;);&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            //Close and dispose of report&lt;br /&gt;          crReportDocument.Close();&lt;br /&gt;          crReportDocument.Dispose();&lt;br /&gt;          &lt;span style="color:teal;"&gt;GC&lt;/span&gt;.Collect();&lt;br /&gt;      }&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;        &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:teal;"&gt;void&lt;/span&gt; ImageTable()&lt;br /&gt;      {&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;            &lt;span style="color:teal;"&gt;ds_Images&lt;/span&gt; Images1 = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;ds_Images&lt;/span&gt;();&lt;br /&gt;          &lt;span style="color:blue;"&gt;string&lt;/span&gt; fileName = &lt;span style="color:maroon;"&gt;@"\\img\a.JPG"&lt;/span&gt;;&lt;br /&gt;          fileName = Server.MapPath(fileName.Trim());&lt;br /&gt;          &lt;span style="color:teal;"&gt;DataRow&lt;/span&gt; row;&lt;br /&gt;          Images1.Tables[0].TableName = &lt;span style="color:maroon;"&gt;"tblImages"&lt;/span&gt;;&lt;br /&gt;          Images1.Tables[0].Columns.Clear();&lt;br /&gt;          Images1.Tables[0].Columns.Add(&lt;span style="color:maroon;"&gt;"img"&lt;/span&gt;, System.&lt;span style="color:teal;"&gt;Type&lt;/span&gt;.GetType(&lt;span style="color:maroon;"&gt;"System.Byte[]"&lt;/span&gt;));&lt;br /&gt;          row = Images1.Tables[0].NewRow();&lt;br /&gt;          &lt;span style="color:teal;"&gt;FileStream&lt;/span&gt; fs = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;FileStream&lt;/span&gt;(fileName, &lt;span style="color:teal;"&gt;FileMode&lt;/span&gt;.Open, &lt;span style="color:teal;"&gt;FileAccess&lt;/span&gt;.Read);&lt;br /&gt;          &lt;span style="color:teal;"&gt;BinaryReader&lt;/span&gt; br = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;BinaryReader&lt;/span&gt;(fs);&lt;br /&gt;          row[0] = br.ReadBytes(&lt;span style="color:teal;"&gt;Convert&lt;/span&gt;.ToInt32(br.BaseStream.Length));&lt;br /&gt;          row[1] = 1;&lt;br /&gt;          Images1.Tables[0].Rows.Add(row);&lt;br /&gt;          br = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;&lt;br /&gt;          fs.Close();&lt;br /&gt;          fs = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;&lt;br /&gt;     }&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;Method II: Using Picture Object of Crystal Report&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;   &lt;/span&gt;&lt;/b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;Using the&lt;b&gt; Dynamic Graphic Location &lt;/b&gt;of picture OLE object of crystal report, we can change picture dynamically at run-time.&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;1. Create a parameter field in the report with string data type.&lt;br /&gt;2 In the report Add a picture OLE object. inside report right click-&gt;Insert-&gt;OLE object- &gt;select Bitmap Image&lt;br /&gt;3 Right click the OLE picture object and select Format Object- &gt;select Picture tab -&gt;Graphic location -&gt; inside it drag the parameter field.&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;in the front end just pass the Image URL to the report&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:teal;"   &gt;ParameterDiscreteValue&lt;/span&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt; crParameterimgLocation;&lt;br /&gt;&lt;u1:p&gt; &lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;color:blue;"   &gt;                string&lt;/span&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt; img_url = &lt;span style="color:maroon;"&gt;@"\\images/newImages/nevadadot.JPG"&lt;/span&gt;;&lt;br /&gt;              img_url = Server.MapPath(img_url);&lt;br /&gt;              crParameterField = crParameterFields[&lt;span style="color:maroon;"&gt;"imgLocation"&lt;/span&gt;];&lt;br /&gt;              crParameterValues = crParameterField.CurrentValues;&lt;br /&gt;              &lt;span style="color:blue;"&gt;this&lt;/span&gt;.crParameterimgLocation = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:teal;"&gt;ParameterDiscreteValue&lt;/span&gt;();&lt;br /&gt;              &lt;span style="color:blue;"&gt;this&lt;/span&gt;.crParameterimgLocation.Value = img_url;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;br /&gt;              //Add current value for the parameter field&lt;br /&gt;              crParameterValues.Add(crParameterimgLocation);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;br /&gt;Note: while passing the Image URL do not put put single quotes.&lt;u1:p&gt;&lt;br /&gt;&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;We can use either method to display the Images in the report dynamically.&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt; In Crystal Reports XI, the 'Dynamic Image Location' feature does not work with images in &lt;b&gt;GIF&lt;/b&gt; format. Why does this behavior occur and how can you resolve it?" This drawback matches to the recordset method too.&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;"To debug the issue&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;This behavior occurs because Crystal Reports XI does not fully support the GIF file format. To resolve this behavior, use a supported image format when working with the 'Dynamic Image Location' feature. Supported image formats are Joint Photographic Experts (JPG), bitmap (BMP), Tagged Image File Format (TIF) and Portable Network Graphics (PNG)."&lt;u1:p&gt;&lt;/u1:p&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:&amp;quot;;font-size:10;"  &gt;&lt;u1:p&gt;&lt;/u1:p&gt;Any comments appreciated&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;span style=""&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=";font-family:Arial;font-size:10;"  &gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7116253520371246712-5018575191576631298?l=natrajt.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/5018575191576631298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7116253520371246712&amp;postID=5018575191576631298' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/5018575191576631298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/5018575191576631298'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/2008/06/dynamic-images-at-runtime-in-crystal.html' title='Dynamic Images at runtime in Crystal Report XI using ASP.Net 2.0'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7116253520371246712.post-8900914750832987371</id><published>2008-05-14T01:16:00.000-07:00</published><updated>2008-09-29T04:45:59.368-07:00</updated><title type='text'>Passing Values between Pages in ASP.Net</title><content type='html'>&lt;span style="font-weight: bold; color: rgb(153, 0, 0);"&gt;Passing values between pages in ASP.Net&lt;br /&gt;&lt;/span&gt;###########################################&lt;br /&gt;&lt;br /&gt; Here are some useful way to pass values between pages. I think it will useful for the beginners who entered in Web development&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1.Response.Redirect&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This maybe the easiest of them all. You start by writing some data in the text field, and when you finish writing the data, you press the button labeled 'Response.Redirect'. One tip that I would like to share with you is, sometimes we want to transfer to another page inside the catch exception, meaning exception is caught and we want to transfer to another page. If you try to do this, it may give you a System.Threading exception. This exception is raised because you are transferring to another page leaving behind the thread running. You can solve this problem using:&lt;br /&gt;&lt;br /&gt;Response.Redirect("WebForm2.aspx",false);&lt;br /&gt;&lt;br /&gt;This tells the compiler to go to page "WebForm2.aspx", and "false" here means that don't end what you were doing on the current page. You should also look at the System.Threading class for threading issues. Below, you can see the C# code of the button event. "txtName" is the name of the text field whose value is being transferred to a page called "WebForm2.aspx". "Name" which is just after "?" sign is just a temporary response variable which will hold the value of the text box.&lt;br /&gt;&lt;br /&gt;private void Button1_Click(object sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;  // Value sent using HttpResponse&lt;br /&gt;  Response.Redirect("WebForm2.aspx?valName="+txtName.Text);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Okay, up till this point, you have send the values using Response. But now, where do I collect the values, so in the "WebForm2.aspx" page_Load event, write this code. First, we check that the value entered is not null. If it's not, then we simply display the value on the page using a Label control. Note: When you use Response.Redirect method to pass the values, all the values are visible in the URL of the browser. You should never pass credit card numbers and confidential information via Response.Redirect.&lt;br /&gt;&lt;br /&gt;if (Request.QueryString["valName"]!= null)&lt;br /&gt;  lblName.Text = Request.QueryString["Name"];&lt;br /&gt;&lt;br /&gt;-------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.Cookies&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next up is cookies. Cookies are created on the server side but saved on the client side. In the button click event of 'Cookies', write this code:&lt;br /&gt;&lt;br /&gt;HttpCookie cName = new HttpCookie("valName");&lt;br /&gt;cName.Value = txtName.Text;&lt;br /&gt;Response.Cookies.Add(cName);&lt;br /&gt;Response.Redirect("WebForm2.aspx");&lt;br /&gt;&lt;br /&gt;First, we create a cookie named "cName". Since one cookie instance can hold many values, we tell the compiler that this cookie will hold "Name" value. We assign to it the value of the TextBox and finally add it in the Response stream, and sent it to the other page using Response.Redirect method.&lt;br /&gt;&lt;br /&gt;Let's see here how we can get the value of the cookie which is sent by one page.&lt;br /&gt;&lt;br /&gt;if (Request.Cookies["valName"] != null )&lt;br /&gt;  lblName.Text = Request.Cookies["valName"].Value;&lt;br /&gt;&lt;br /&gt;As you see, it's exactly the same way as we did before, but now we are using Request.Cookies instead of Request.QueryString. Remember that some browsers don't accept cookies.&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;3.Session Variables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next we see the session variables which are handled by the server. Sessions are created as soon as the first response is being sent from the client to the server, and session ends when the user closes his browser window or some abnormal operation takes place. Here is how you can use session variables for transferring values. Below you can see a Session is created for the user and "Name" is the key, also known as the Session key, which is assigned the TextBox value.&lt;br /&gt;&lt;br /&gt;// Session Created&lt;br /&gt;Session["Name"] = txtName.Text;&lt;br /&gt;Response.Redirect("WebForm2.aspx");&lt;br /&gt;&lt;br /&gt;// The code below shows how to get the session value.&lt;br /&gt;// This code must be placed in other page.&lt;br /&gt;if(Session["Name"] != null)&lt;br /&gt;  Label3.Text = Session["Name"].ToString();&lt;br /&gt;&lt;br /&gt;It is best practice to declare all your session variables in the global.asax file, in the session_start() event, so it will available for your whole application.&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4.Application Variables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Sometimes, we need to access a value from anywhere in our page. For that, you can use Application variables. Here is a small code that shows how to do that. Once you created and assigned the Application variable, you can retrieve its value anywhere in your application.&lt;br /&gt;&lt;br /&gt;// This sets the value of the Application Variable&lt;br /&gt;Application["valName"] = txtName.Text;&lt;br /&gt;Response.Redirect("WebForm2.aspx");&lt;br /&gt;&lt;br /&gt;// This is how we retrieve the value of the Application Variable&lt;br /&gt;if( Application["valName"] != null )&lt;br /&gt;  lblName.Text = Application["valName"].ToString();&lt;br /&gt;&lt;br /&gt;-----------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.HttpContext&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can also use HttpContext to retrieve values from pages. The values are retrieved using properties or methods. It's a good idea to use properties since they are easier to code and modify. In your first page, make a property that returns the value of the TextBox.&lt;br /&gt;&lt;br /&gt;public string GetName&lt;br /&gt;{&lt;br /&gt;  get { return txtName.Text; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;We will use Server.Transfer to send the control to a new page. Note that Server.Transfer only transfers the control to the new page and does not redirect the browser to it, which means you will see the address of the old page in your URL. Simply add the following line of code in 'Server.Transfer' button click event:&lt;br /&gt;&lt;br /&gt;Server.Transfer("WebForm2.aspx");&lt;br /&gt;&lt;br /&gt;Now, let's go to the page where the values are being transferred, which in this case is "webForm2.aspx".&lt;br /&gt;&lt;br /&gt;// You can declare this Globally or in any event you like&lt;br /&gt;WebForm1 w;&lt;br /&gt;&lt;br /&gt;// Gets the Page.Context which is Associated with this page&lt;br /&gt;w = (WebForm1)Context.Handler;&lt;br /&gt;// Assign the Label control with the property "GetName" which returns string&lt;br /&gt;lblName.Text = w.GetName;&lt;br /&gt;&lt;br /&gt;============================================================&lt;br /&gt;&lt;br /&gt;Hope it will helpful for you&lt;br /&gt;&lt;br /&gt;any comments appreciated&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7116253520371246712-8900914750832987371?l=natrajt.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/8900914750832987371/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7116253520371246712&amp;postID=8900914750832987371' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/8900914750832987371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/8900914750832987371'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/2008/05/passing-values-between-pages-in-aspnet.html' title='Passing Values between Pages in ASP.Net'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7116253520371246712.post-7324187429479109832</id><published>2008-05-14T01:07:00.000-07:00</published><updated>2008-05-14T01:13:17.322-07:00</updated><title type='text'>Secure PDF Files and opening reports in a new window in ASP.Net 2.0</title><content type='html'>&lt;span style=";font-family:Arial;font-size:85%;"  &gt; The main concern we faced while  handling the PDF file is its security.We export the crystal report into PDF file  and rendered in the browser. After viewing the PDF file anyone can access the  PDF if they came to know the path. After analyzed a lot of methods we concluded  with the below solution. It is easy to implement and feel happy to share this  with you all the experts.&lt;/span&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;              During the analysis I came to know  various ways to secure the PDF files such as Form authentication,storing the PDF  files in other secure formats(like .recourse) and while calling the PDF file  just save as the file into PDF and rendered using  Response.WriteFile method,  using session Id with the PDF file name and a few more.&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;strong&gt;For the stored PDF files or the Crystal  reports need to generate and to be stored in a external device for the future  purpose&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;We can use the below methods&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;1.Create a separate page &lt;span style="color: rgb(128, 0, 0);"&gt;'SecurePdf.aspx'&lt;/span&gt;. we can use this page for entire  application&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;2.Place a Iframe control&lt;br /&gt;&lt;/span&gt;&lt;code&gt;&lt;/code&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;&lt;span style="color: rgb(128, 0, 0);"&gt;    iframe id="fraPdfRender" runat="server" height="800" scrolling="auto" width="100%"&lt;/span&gt;&lt;/span&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;3.If crystal report need to rendered as a PDF file,  first convert that into PDF file using the export method of crystal document and  use the below code on the required page which the report or the PDF file need to  rendered . It will open the &lt;span style="color: rgb(128, 0, 0);"&gt;'SecurePdf.aspx'&lt;/span&gt; in a  separate window (the popup blocker should allow this site, or if it is not  required to open in a new window use the normal response.redirect method for  opening the page) &lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;                    &lt;span style="color: rgb(128, 0, 0);"&gt;    string  url = reportfilename;&lt;br /&gt;                      Session["securePdf"] =  url;&lt;br /&gt;                      string script =  "window.open('/reports/securePdf/SecurePdf.aspx','new_Win');";&lt;br /&gt;                       ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script,  true);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;4.place this code in the code behind  file&lt;br /&gt;               &lt;span style="color: rgb(128, 0, 0);"&gt;string url =  Session["securePdf_n"].ToString();&lt;br /&gt;               HtmlControl frame1 =  (HtmlControl)this.FindControl("fraPdfRender");&lt;br /&gt;                frame1.Attributes["src"] = url; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;I believe this code is easy to impalement and the  url of the PDF file is not shown to the user.I implemented into my application  but didn't get the feedback from my client.&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;strong&gt;If Crystal reports needs to generate for  on demand as PDF file:&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;after analyzed some I used the below  method&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style="color: rgb(128, 0, 0);font-family:Arial;font-size:85%;"  &gt;ReportDocument  crReportDocument;&lt;br /&gt;crReportDocument = new cReportName();&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style="color: rgb(128, 0, 0);font-family:Arial;font-size:85%;"  &gt;crReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat,HttpResponse,false);&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;this will convert the crystal report into PDF  automatically and render into the browser without storing in a external  disk.&lt;/span&gt;&lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt; &lt;/span&gt;&lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;&lt;br /&gt;Believe it will helpful for the secure PDF file handling , rendering  the Crystal report as PDF file and for opening  the report in separate  window.&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style=";font-family:Arial;font-size:85%;"  &gt;As comments and opinion always expected from you &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7116253520371246712-7324187429479109832?l=natrajt.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://natrajt.blogspot.com/feeds/7324187429479109832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7116253520371246712&amp;postID=7324187429479109832' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/7324187429479109832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7116253520371246712/posts/default/7324187429479109832'/><link rel='alternate' type='text/html' href='http://natrajt.blogspot.com/2008/05/secure-pdf-files-and-opening-reports-in_14.html' title='Secure PDF Files and opening reports in a new window in ASP.Net 2.0'/><author><name>Natarajan Thangavel(Cool Baby)</name><uri>http://www.blogger.com/profile/10072610283607925743</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://bp0.blogger.com/_Qxz0gScs2sk/SCqLtINoW2I/AAAAAAAAACM/NwKSEnUzLzM/S220/attachment_12.jpg'/></author><thr:total>0</thr:total></entry></feed>
