| |
Data Dynamics Reports Support
Started by JAdauto at 06-25-2009 9:23 PM. Topic has 5 replies.
 
 
 
|
|
Sort Posts:
|
|
|
|
06-25-2009, 9:23 PM
|
JAdauto
Joined on 02-11-2009
Posts 20
|
|
|
I have created a reports app that stores the report files in binary format in the database and then displays a list of all those reports. The client can double click to open a report in the ReportViewer (where it will "unload" the report from binary format back to report format) and display, or the user can open the report in the Designer and make changes to it. When I get the report image from the database, I am saving it to the local C drive. The problem I am having is when I am trying to delete the report file from the C drive. I am using the following code in the FormClosed event to delete the file:
If System.IO.File.Exists(ms_FilePathName) = True Then
System.IO.File.Delete(ms_FilePathName)
End If
However, I get the following error:
The process cannot access the file 'c:\rptMemberFamilyListing.rdlx' because it is being used by another process.
I am sure this is because the file is being closed on the Viewer or designer form, but I thought being in formClosed, it would be done with it, however, that must not be the case. Is there something special I have to do to release this report file???
Thanks!
|
|
|
|
|
Report
|
|
|
|
06-26-2009, 7:38 AM
|
JAdauto
Joined on 02-11-2009
Posts 20
|
|
|
Let me add that this Delete code works about 90% of the time on the Form with the Viewer and successfully deletes without error about being in use. However, on the designer form, it will never delete the file due to error.
|
|
|
|
|
Report
|
|
|
|
06-26-2009, 12:48 PM
|
JAdauto
Joined on 02-11-2009
Posts 20
|
|
|
To add further, I have tried adding:
lb_Destroyed = Me.ReportDesigner.DestroyDesigner()
to the DeleteFile routine and only run it if lb_Destroyed = True, which it does. Any idea what is still holding this file open that it cannot be deleted?
|
|
|
|
|
Report
|
|
|
|
06-30-2009, 7:50 AM
|
Amit Pal
Joined on 12-11-2008
Posts 517

|
|
|
Hello,
Please find attached a sample application in which I have implemented the desired functionality. This application depicts underline steps:
(1) Run the application and select any of the two reports (from the database) and load it in the ReportPreview.
(2) This will create an RDLX (sample.rdlx) in C: drive.
(3) Now, click on ‘Load Designer Form’ button. This will load another form with userDesignerControl in it. The saved report will be loaded now in the userDesignerControl.
(4) Now, go ahead and close this form. The Form_Closed event of this form has this code:
if (System.IO.File.Exists("C:\\sample.rdlx"))
System.IO.File.Delete("C:\\sample.rdlx");
(5) You will find that the RDLX will be successfully deleted from the physical drive.
If you are doing it in any other way or still facing the same issue then please modify the attached sample and send it back to us.
I have tested this with version 1.6.1296.0.
Regards,
Amit
Amit Pal GrapeCity- DataDynamics
|
|
|
|
|
Report
|
|
|
|
07-02-2009, 10:56 PM
|
JAdauto
Joined on 02-11-2009
Posts 20
|
|
|
do you have an example of this code using .net? I have been able to get pieces from it but I am unable to run it because I dont have that program.
My code looks like this currently:
Select ml_ReportType
Case ReportTypeENUM.rtSystem
Me.ReportsTableAdapter.FillByID(DSReports.Reports, ml_ReportID)
lo_ReportData = Me.DSReports.Reports.FindByID(ml_ReportID)
ls_ReportDesc = lo_ReportData.Description
ls_FileName = lo_ReportData.ReportName
ls_FileName = ms_FILEPATH & ls_FileName
ReportDataByte = lo_ReportData.Report
Case ReportTypeENUM.rtClubCustom
lo_CustomReportData = Me.DSCustom.CustomReport.FindByID(ml_ReportID)
ls_ReportDesc = lo_CustomReportData.Description
ls_FileName = lo_CustomReportData.ReportName
ls_FileName = ms_FILEPATH & ls_FileName
ReportDataByte = lo_CustomReportData.Report
End Select
ll_FileLength = UBound(ReportDataByte)
ll_FileLength = ll_FileLength + 1
Dim fs As FileStream = New FileStream(ls_FileName, _
FileMode.OpenOrCreate, _
FileAccess.ReadWrite)
fs.Write(ReportDataByte, 0, ll_FileLength)
fs.Close()
ms_FilePathName = ls_FileName
Dim fsn As FileStream = New FileStream(ms_FilePathName, _
FileMode.OpenOrCreate, _
FileAccess.ReadWrite)
Dim sr As StreamReader = New StreamReader(fsn)
Dim def As ReportDefinition = New ReportDefinition(sr)
'Dim f1 As New System.IO.FileInfo(ms_FilePathName)
Dim f1 As New System.IO.FileInfo(ms_FilePathName)
ls_Sourcename = MDataAccess.GetDataSourceName
ls_UserID = MDataAccess.GetUserID
ls_Password = MDataAccess.GetPassword
ls_ConnectionString = ""
ls_ConnectionString = ls_ConnectionString & "data source=" & ls_Sourcename & ";"
ls_ConnectionString = ls_ConnectionString & "user id=" & ls_UserID & ";"
ls_ConnectionString = ls_ConnectionString & "password =" & ls_Password & ";"
def.Report.DataSources(0).ConnectionProperties.ConnectString = ls_ConnectionString
def.Report.DataSources(0).ConnectionProperties.DataProvider = "SQL"
'Me.ReportDesigner.LoadReport(ms_FilePathName)
Me.ReportDesigner.LoadReport(f1)
fs.Close()
sr.Close()
fs = Nothing
lo_ReportData = Nothing
I added the new lines that use the System.IO.FileInfo instead of just sending the file name to LoadReport.
The code now opens the designer and puts the name at the top in the title bar, but does not open the report. I am now closing and deleting the report fine from the local c, but now it is just not opening the report in the designer, or at least not where i can see any report design.
thanks for any help you may have.
|
|
|
|
|
Report
|
|
|
|
07-07-2009, 3:40 AM
|
Amit Pal
Joined on 12-11-2008
Posts 517

|
|
|
“do you have an example of this code using .net?”
It seems that you are using VB.NET and earlier I have provided the code snippet in C#.
Here is the code snippet which you may use in the ListBox SelectedIndexChanged event:
'Instanatiate a new String
Dim rdlx As String
'Listbox Selected item is passed to this RDLX
rdlx = Me.ReportInDBDataSet1.DDRReports.Rows(Me.ListBox1.SelectedIndex).ItemArray(2).ToString()
'Pass the RDLX to the TextReader object
Dim tr As System.IO.TextReader = New System.IO.StringReader(rdlx)
'Pass the TextReader to the ReportDefinition
Dim def As New DataDynamics.Reports.ReportDefinition(tr)
'Pass the ReportDefinition to the Reportruntime
Dim rrt As New DataDynamics.Reports.ReportRuntime(def)
'Open the report in the preview
ReportPreview1.OpenReport(rrt, ListBox1.SelectedItem.ToString())
Dim f1 As New System.IO.FileInfo("C:\Sample.rdlx")
'Save the opened report into physical drive
def.Save(f1)
tr.Close()
tr = Nothing
This will open the report in the reportpreview as well as save a copy in the physical drive as well. Before this, you need to make a connection to the database where the report files reside.
After a copy of the report gets saved, then you may delete it through following code:
If System.IO.File.Exists("C:\sample.rdlx") Then
System.IO.File.Delete("C:\sample.rdlx")
End If
Regards,
Amit
Amit Pal GrapeCity- DataDynamics
|
|
|
|
|
Report
|
|
|
|
|
GrapeCity » Product Support » Data Dynamics R... » Close Report File
|
|
|
|
|