1. Tiago Miranda
  2. PowerBuilder
  3. Monday, 25 July 2022 15:51 PM UTC

Hello how are you ?
I'm facing difficulties to delete files with PDF extension generated in a temporary folder on my machine.
These files are generated using the Datawindow/DataStore SaveAs function.
I generate these files and put them in a vector to be able to delete them later. A timer is running that calls the function to delete the files, but when it tries to delete, it returns FALSE and does not delete.
If I try to delete it by entering the folder and delete it, it says that the file is in use by Powerbuilder.

I even used a Yield() Sleep() to see if it worked and it isn't.
It happens that this routine worked and now it doesn't work anymore, the files are always "locked" by the powerbuilder and to be able to delete it I have to close the IDE to delete them from the folder.

 

LONG nFor
STRING sArrayAux[]

for nFor = 1 to 2
	sleep(1)
	Yield()
next

FOR nFor = 1 TO UpperBound( i_sApagarArquivo ) 
		IF FileExists ( i_sApagarArquivo[nFor] ) THEN 
			IF FileDelete( i_sApagarArquivo[nFor] ) THEN
				SetNull( i_sApagarArquivo[nFor] )
			ELSE
				sArrayAux[ UpperBound( sArrayAux ) +1 ] = i_sApagarArquivo[nFor]
			END IF
		END IF	
NEXT

i_sApagarArquivo = sArrayAux
dsDll = CREATE datastore 
	dsDll.DataObject = "d_rastreamento_laudo_print"
	dsDll.SetTransObject( SQLCA )
	dsDll.Retrieve(nOsmSerieArr[nAux], nOsmNumArr[nAux], nSmmNumArr[nAux])
	
	IF dsDll.RowCount() > 0  then
		
		sFileHIst = "\smart\temp\" + f_generateGUID() +"_rastreamento.pdf"
		dsDll.Object.DataWindow.Export.PDF.Method = NativePDF!
		dsDll.SaveAs ( sFileHIst, PDF!, true )

		
		dthrRcls[nAux] = odt.RelativeTime( dthrRcls[nAux], 00:00:03 )
		
		i_s_pdfFiles.sfilename[UpperBound(i_s_pdfFiles.sfilename) + 1] = sFileHIst
		i_s_pdfFiles.dtini[UpperBound(i_s_pdfFiles.dtini) + 1] = dthrRcls[nAux]	
		
	END IF



Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 25 July 2022 16:25 PM UTC
  2. PowerBuilder
  3. # 1

Hi Tiago;

   That sounds like the PBVM is not doing a proper CLOSE on the file after a SaveAs() operation using the "NativePDF" option.

   Please open a Support Ticket for this issue. Especially, if you can replicate this issue in PB2021. 

   Does this issue occur when running from an EXE?

Regards ... Chris 

Comment
  1. Tiago Miranda
  2. Monday, 25 July 2022 17:07 PM UTC
Hello, it occurs both running through the IDE and through the generated executable.



I can only delete the file in the folder, if I go to the folder, click on the file and send it to the trash, but always after closing the IDE or closing the .exe execution.
  1. Helpful
  1. Tiago Miranda
  2. Monday, 25 July 2022 17:43 PM UTC
I just opened a support ticket. Thanks.
  1. Helpful
  1. RITESH KUMAR
  2. Wednesday, 20 November 2024 08:47 AM UTC
Hi @Tiago Miranda,

Could you please share the ticket id and resolution for the issue, I am also getting the similar issue.

Regards

Ritesh

  1. Helpful
There are no comments made yet.
Tiago Miranda Accepted Answer Pending Moderation
  1. Monday, 25 July 2022 17:07 PM UTC
  2. PowerBuilder
  3. # 2
Hello, it occurs both running through the IDE and through the generated executable.

I can only delete the file in the folder, if I go to the folder, click on the file and send it to the trash, but always after closing the IDE or closing the .exe execution.
Comment
  1. John Fauss
  2. Monday, 25 July 2022 17:38 PM UTC
You said "...this routine worked..." - In an earlier version of PB? Windows? I agree with Chris, this sounds like a bug in PB where it is not closing the PDF file created by the SaveAs. Also, I do not believe the Sleep() and Yield() calls are needed, since the SaveAs function call is not going to return to your code until it has finished its work. I can understand why you tried calling them, however.
  1. Helpful
  1. Tiago Miranda
  2. Monday, 25 July 2022 17:41 PM UTC
it worked in the same version as it is now...

Mysteriously stopped working and leaving files stuck.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 25 July 2022 17:41 PM UTC
I agree John.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Monday, 25 July 2022 19:53 PM UTC
  2. PowerBuilder
  3. # 3

Tiago - 

How are you able to test this issue in both 2019 R2 and R3? On separate development machines? I'm a little confused by this as both releases cannot co-exist on the same machine.

With R3 and later versions, you can switch the IDE and the compiled application to utilize other versions of the runtime, but not to any version/release prior to 2019 R3.

Is it possible you are running the IDE and app with a mixture of 2019 R2 and 2019 R3 runtime DLL's? If so, this will not work.

Did you happen to install a later maintenance release for 2019 R3?

Regards, John

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Monday, 25 July 2022 21:42 PM UTC
  2. PowerBuilder
  3. # 4

What Chris said:  the code is not CLOSING the file correctly or completely.

One trick that might work is to POST the command to delete these files. If the IDE or the EXE is holding the files open, this will not work, but it's worth a try.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 26 July 2022 23:55 PM UTC
  2. PowerBuilder
  3. # 5

What filesize do you get after saveAs()?

One explanation would be that you're writing 0 byte files (incorrect files). Those cannot be deleted.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.