|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
exporting pdf in vs.net
<i><b>Originally posted by : David (dparry@calibresys.com)</b></i><br /><br />when exporting, i keep getting an error "logon failed". My report works fine otherwise, conn works and pulls data from db fine so conn established. Do I need to repass login info?<br />Code behind below:<br /><br />'oledb connection and access the report w/shared and engine<br />Imports CrystalDecisions.Shared<br />Imports CrystalDecisions.CrystalReports.Engine<br />Imports System.Data.OleDb<br /><br />Public Class ODTMSCReport<br /> Inherits System.Web.UI.Page<br /> Protected WithEvents cboFY As System.Web.UI.WebControls.DropDownList<br /> Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer<br /> Protected WithEvents Button1 As System.Web.UI.WebControls.Button<br /> Protected WithEvents cboMSC As System.Web.UI.WebControls.DropDownList<br /><br />#Region " Web Form Designer Generated Code "<br /><br /> 'This call is required by the Web Form Designer.<br /> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br /><br /> End Sub<br /><br /> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<br /> 'CODEGEN: This method call is required by the Web Form Designer<br /> 'Do not modify it using the code editor.<br /> InitializeComponent()<br /> <br /> End Sub<br /><br />#End Region<br /><br /> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br /> Dim strWhere As String<br /><br /> 'set up connection<br /> Dim oleConn As New OleDbConnection("Provider=SQLOLEDB;Data Source=servernamehere;UID=myuserid;PASSWORD=mypass word;Initial Catalog=yadaya")<br /> Dim oleAdapter As New OleDbDataAdapter()<br /> Dim myCommand As OleDbCommand<br /> oleConn.Open()<br /><br /> If Not Page.IsPostBack Then<br /> '-- Load MSC List and default to nothing so i can later default to "1ST PERSCOM" and fy02<br /> myCommand = New OleDbCommand("Select Distinct MSC FROM MSC", oleConn)<br /> Dim myReader As OleDbDataReader = myCommand.ExecuteReader()<br /> cboMSC.DataSource = myReader<br /> cboMSC.DataTextField = "MSC"<br /> cboMSC.DataValueField = "MSC"<br /> cboMSC.DataBind()<br /> myReader.Close()<br /> If cboMSC.SelectedIndex > 0 Then<br /> cboMSC.SelectedItem.Value = ""<br /> End If<br /> ' cboMSC.Items(1).Selected = "TRUE"<br /> '[ cboMSC.Items.Insert(0, "")<br /><br /> '-- Load FY List,defaulted to null and i set default to fy02 below<br /> myCommand = New OleDbCommand("Select DISTINCT FY From ODTPLAN", oleConn)<br /> myReader = myCommand.ExecuteReader()<br /> cboFY.DataSource = myReader<br /> cboFY.DataTextField = "FY"<br /> cboFY.DataValueField = "FY"<br /> cboFY.DataBind()<br /> myReader.Close()<br /> If cboFY.SelectedIndex > 0 Then<br /> cboFY.SelectedItem.Value = ""<br /> End If<br /> 'cboFY.Items.Insert(0, "")<br /> End If<br /><br /> If cboMSC.SelectedIndex > -1 Then<br /> strWhere = " MSC = '" & cboMSC.SelectedItem.Value & "'"<br /> End If<br /><br /> If cboFY.SelectedIndex > 0 Then<br /> strWhere += " AND FY = '" & cboFY.SelectedItem.Value & "'"<br /> End If<br /><br /> Dim MSC As String<br /> Dim FY As String<br /> MSC = cboMSC.SelectedItem.Value<br /> FY = cboFY.SelectedItem.Value<br /><br /> oleAdapter.SelectCommand = New OleDbCommand("select * , '" & MSC & "' AS MSC1, '" & FY & "' AS FY1 from vwODToccmsc where " & strWhere, oleConn)<br /><br /> ' Connect to the data source, fetch the data, and disconnect from the database.<br /> Dim DataSet As New DataSet()<br /> oleAdapter.Fill(DataSet, "vwODToccmsc")<br /><br /> Dim oRpt As New ODTMSCrpt()<br /> oRpt.Load()<br /> oRpt.SetDataSource(DataSet)<br /> CrystalReportViewer1.ReportSource = oRpt<br /> CrystalReportViewer1.DataBind()<br /><br /> DataSet.Dispose()<br /> DataSet = Nothing<br /> oleAdapter.Dispose()<br /> oleAdapter = Nothing<br /> oleConn.Dispose()<br /> oleConn = Nothing<br /><br /><br /> 'Dim strWhere As String<br /> 'Dim Filter As FilterSetting<br /> 'get the drop-down value of MSC<br /> 'If Len(Trim(cboMSC.SelectedIndex)) > 0 Then<br /> ' Filter.MSC = cboMSC.SelectedItem.Value<br /> ' Filter.MSC = Trim(Request.Form("cboMSC"))<br /> ' strWhere = "MSC " & Trim(Request.Form("cboMSC")) & " " & cboMSC.SelectedItem.Value & " AND "<br /> 'End If<br /><br /> 'get the drop-down value of FY<br /> 'If Len(Trim(cboFY.SelectedIndex)) > 0 Then<br /> ' Filter.FY = cboFY.SelectedItem.Value<br /> ' Filter.FY = Request.Form("cboFY")<br /> ' strWhere += "FY " & Request.Form("cboFY") & " '" & cboFY.SelectedItem.Value & "'"<br /> 'End If<br /><br /> End Sub<br /><br /> '------------------------------<br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br /> Dim oRpt As ODTMSCrpt = New ODTMSCrpt()<br /> 'Dim DataSet As New DataSet()<br /> 'myReport.SetDataSource(DataSet)<br /> 'Note : we are creating an instance of the strongly-typed Crystal Report file here.<br /> Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions ()<br /> orpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.Disk File<br /><br /> ' You also have the option to export the report to other sources<br /> ' like Microsoft Exchange, MAPI, etc. <br /> oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableD ocFormat<br /><br /> 'Here we are exporting the report to a .pdf format. You can<br /> ' also choose any of the other formats specified above. <br /><br /> DiskOpts.DiskFileName = "c:Output.pdf"<br /><br /> 'If you do not specify the exact path here (i.e. including<br /> ' the drive and Directory),<br /> 'then you would find your output file landing up in the<br /> 'c:WinNTSystem32 directory - atleast in case of a<br /> ' Windows 2000 System<br /><br /> oRpt.ExportOptions.DestinationOptions = DiskOpts<br /><br /> 'The Reports Export Options does not have a filename property<br /> 'that can be directly set. Instead, you will have to use<br /> 'the DiskFileDestinationOptions object and set its DiskFileName<br /> 'property to the file name (including the path) of your choice.<br /> 'Then you would set the Report Export Options<br /> 'DestinationOptions property to point to the<br /> 'DiskFileDestinationOption object. <br /> oRpt.Export()<br /><br /> 'This statement exports the report based on the previously set properties. <br /> End Sub<br /><br /><br />End Class<br /><br />
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : </b></i><br /><br />The report is exported to the server, do you have the permission to write on the server?<br /><br />------------<br />David at 3/15/2002 4:14:39 PM<br /><br /><br />when exporting, i keep getting an error "logon failed". My report works fine otherwise, conn works and pulls data from db fine so conn established. Do I need to repass login info?<br />Code behind below:<br /><br />'oledb connection and access the report w/shared and engine<br />Imports CrystalDecisions.Shared<br />Imports CrystalDecisions.CrystalReports.Engine<br />Imports System.Data.OleDb<br /><br />Public Class ODTMSCReport<br /> Inherits System.Web.UI.Page<br /> Protected WithEvents cboFY As System.Web.UI.WebControls.DropDownList<br /> Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer<br /> Protected WithEvents Button1 As System.Web.UI.WebControls.Button<br /> Protected WithEvents cboMSC As System.Web.UI.WebControls.DropDownList<br /><br />#Region " Web Form Designer Generated Code "<br /><br /> 'This call is required by the Web Form Designer.<br /> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br /><br /> End Sub<br /><br /> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init<br /> 'CODEGEN: This method call is required by the Web Form Designer<br /> 'Do not modify it using the code editor.<br /> InitializeComponent()<br /> <br /> End Sub<br /><br />#End Region<br /><br /> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br /> Dim strWhere As String<br /><br /> 'set up connection<br /> Dim oleConn As New OleDbConnection("Provider=SQLOLEDB;Data Source=servernamehere;UID=myuserid;PASSWORD=mypass word;Initial Catalog=yadaya")<br /> Dim oleAdapter As New OleDbDataAdapter()<br /> Dim myCommand As OleDbCommand<br /> oleConn.Open()<br /><br /> If Not Page.IsPostBack Then<br /> '-- Load MSC List and default to nothing so i can later default to "1ST PERSCOM" and fy02<br /> myCommand = New OleDbCommand("Select Distinct MSC FROM MSC", oleConn)<br /> Dim myReader As OleDbDataReader = myCommand.ExecuteReader()<br /> cboMSC.DataSource = myReader<br /> cboMSC.DataTextField = "MSC"<br /> cboMSC.DataValueField = "MSC"<br /> cboMSC.DataBind()<br /> myReader.Close()<br /> If cboMSC.SelectedIndex > 0 Then<br /> cboMSC.SelectedItem.Value = ""<br /> End If<br /> ' cboMSC.Items(1).Selected = "TRUE"<br /> '[ cboMSC.Items.Insert(0, "")<br /><br /> '-- Load FY List,defaulted to null and i set default to fy02 below<br /> myCommand = New OleDbCommand("Select DISTINCT FY From ODTPLAN", oleConn)<br /> myReader = myCommand.ExecuteReader()<br /> cboFY.DataSource = myReader<br /> cboFY.DataTextField = "FY"<br /> cboFY.DataValueField = "FY"<br /> cboFY.DataBind()<br /> myReader.Close()<br /> If cboFY.SelectedIndex > 0 Then<br /> cboFY.SelectedItem.Value = ""<br /> End If<br /> 'cboFY.Items.Insert(0, "")<br /> End If<br /><br /> If cboMSC.SelectedIndex > -1 Then<br /> strWhere = " MSC = '" & cboMSC.SelectedItem.Value & "'"<br /> End If<br /><br /> If cboFY.SelectedIndex > 0 Then<br /> strWhere += " AND FY = '" & cboFY.SelectedItem.Value & "'"<br /> End If<br /><br /> Dim MSC As String<br /> Dim FY As String<br /> MSC = cboMSC.SelectedItem.Value<br /> FY = cboFY.SelectedItem.Value<br /><br /> oleAdapter.SelectCommand = New OleDbCommand("select * , '" & MSC & "' AS MSC1, '" & FY & "' AS FY1 from vwODToccmsc where " & strWhere, oleConn)<br /><br /> ' Connect to the data source, fetch the data, and disconnect from the database.<br /> Dim DataSet As New DataSet()<br /> oleAdapter.Fill(DataSet, "vwODToccmsc")<br /><br /> Dim oRpt As New ODTMSCrpt()<br /> oRpt.Load()<br /> oRpt.SetDataSource(DataSet)<br /> CrystalReportViewer1.ReportSource = oRpt<br /> CrystalReportViewer1.DataBind()<br /><br /> DataSet.Dispose()<br /> DataSet = Nothing<br /> oleAdapter.Dispose()<br /> oleAdapter = Nothing<br /> oleConn.Dispose()<br /> oleConn = Nothing<br /><br /><br /> 'Dim strWhere As String<br /> 'Dim Filter As FilterSetting<br /> 'get the drop-down value of MSC<br /> 'If Len(Trim(cboMSC.SelectedIndex)) > 0 Then<br /> ' Filter.MSC = cboMSC.SelectedItem.Value<br /> ' Filter.MSC = Trim(Request.Form("cboMSC"))<br /> ' strWhere = "MSC " & Trim(Request.Form("cboMSC")) & " " & cboMSC.SelectedItem.Value & " AND "<br /> 'End If<br /><br /> 'get the drop-down value of FY<br /> 'If Len(Trim(cboFY.SelectedIndex)) > 0 Then<br /> ' Filter.FY = cboFY.SelectedItem.Value<br /> ' Filter.FY = Request.Form("cboFY")<br /> ' strWhere += "FY " & Request.Form("cboFY") & " '" & cboFY.SelectedItem.Value & "'"<br /> 'End If<br /><br /> End Sub<br /><br /> '------------------------------<br /> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br /> Dim oRpt As ODTMSCrpt = New ODTMSCrpt()<br /> 'Dim DataSet As New DataSet()<br /> 'myReport.SetDataSource(DataSet)<br /> 'Note : we are creating an instance of the strongly-typed Crystal Report file here.<br /> Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions ()<br /> orpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.Disk File<br /><br /> ' You also have the option to export the report to other sources<br /> ' like Microsoft Exchange, MAPI, etc. <br /> oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableD ocFormat<br /><br /> 'Here we are exporting the report to a .pdf format. You can<br /> ' also choose any of the other formats specified above. <br /><br /> DiskOpts.DiskFileName = "c:Output.pdf"<br /><br /> 'If you do not specify the exact path here (i.e. including<br /> ' the drive and Directory),<br /> 'then you would find your output file landing up in the<br /> 'c:WinNTSystem32 directory - atleast in case of a<br /> ' Windows 2000 System<br /><br /> oRpt.ExportOptions.DestinationOptions = DiskOpts<br /><br /> 'The Reports Export Options does not have a filename property<br /> 'that can be directly set. Instead, you will have to use<br /> 'the DiskFileDestinationOptions object and set its DiskFileName<br /> 'property to the file name (including the path) of your choice.<br /> 'Then you would set the Report Export Options<br /> 'DestinationOptions property to point to the<br /> 'DiskFileDestinationOption object. <br /> oRpt.Export()<br /><br /> 'This statement exports the report based on the previously set properties. <br /> End Sub<br /><br /><br />End Class<br /><br />
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > exporting pdf in vs.net |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|