Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jun 09, 2023 9:30 am

Hello, in the code below sometimes (randomly) the file saving fails, with this error message:
"The requested operation cannot be performed on a file with a user-mapped section open."
This is the code:
Dim dirInfoM As New System.IO.DirectoryInfo(DirPdfSingoliData)

Dim FilesSingoli As String = "ServizioExtra *"
fileInfoMs = dirInfoM.GetFiles(FilesSingoli)
Dim fInfoM As New System.Collections.Generic.List(Of System.IO.FileInfo)()
fInfoM.AddRange(fileInfoMs)

Dim nomefileunico As String = PercorsoOrigine & "\Extra " & _
StrDup(2 - Len(LTrim(RTrim(Day(DataServizio)))), "0") & LTrim(RTrim(Convert.ToString(Day(DataServizio)))) & "-" & _
StrDup(2 - Len(LTrim(RTrim(Month(DataServizio)))), "0") & LTrim(RTrim(Convert.ToString(Month(DataServizio)))) & "-" & _
LTrim(RTrim(Convert.ToString(Year(DataServizio)))) & ".pdf"

For Each filettoM As System.IO.FileInfo In fInfoM
If Not My.Computer.FileSystem.FileExists(nomefileunico) Then
Dim documentovuoto As New PdfDocument()
documentovuoto.LoadFromFile(DirPdfSingoliData & "\" & filettoM.Name)
documentovuoto.SaveToFile(nomefileunico)
documentovuoto.Close()
documentovuoto.Dispose()
documentovuoto = Nothing
Else

' questo funziona con numero di pagine illimitate per pdf:
Dim files As String() = New String() {nomefileunico, DirPdfSingoliData & "\" & filettoM.Name}
Try
Dim docs(files.Length - 1) As PdfDocument
docs(0) = New PdfDocument(files(0))
docs(1) = New PdfDocument(files(1))
For npagina = 0 To docs(1).Pages.Count - 1
docs(0).InsertPage(docs(1), npagina)
Next

docs(0).SaveToFile(nomefileunico, Spire.Pdf.FileFormat.PDF)
docs(0).Close()
docs(0).Dispose()

docs(1).Close()
docs(1).Dispose()

docs = Nothing
files = Nothing

Catch ex As Exception
Messaggio = New DataCenter.Classi.Oggetti.Utilita.Messaggio
Messaggio.IdTipo = DataCenter.Classi.Oggetti.Utilita.Messaggio.TipoMessaggio.TMErrore
Messaggio.Testo = "Errore in lettura scrittura pdf, il file è impegnato da altro utente o ci sono limitazioni di accesso. " & ex.Message
objLabelMessaggioErrore.Text = "Errore in lettura scrittura pdf, il file è impegnato da altro utente o ci sono limitazioni di accesso. " & ex.Message
Messaggi.Add(Messaggio)
Messaggio = Nothing
ScritturaPdfServizioExtraGiornalieroAS400 = False
Exit Function
End Try

End If

Next

It happens even if I save the file into another directory, and I'm sure nobody is accessing it while the saving is done.
The datas in the files to write are always the same.
Can you please help me?
thank you in advance,
Paola

paolagumi
 
Posts: 85
Joined: Tue Apr 21, 2015 11:32 am

Mon Jun 12, 2023 9:38 am

Hello,

Sorry for the late reply due to the weekend.
I tested your code with our latest Spire.PDF Pack(Hot Fix) Version:9.6.0, but I did not reproduce your issue. If you were using an old version, please upgrade to the latest version and try again. If your issue still exists after trying, please provide us with the following information for further investigation. Thank you in advance.
1) Your test environment, such as operating system information (e.g. Windows 10, 64-bit) and locale Settings (e.g. China, Chinese);
2) Your application type, such as console application (. NET Framework 4.5);
3) Your test files.

Sincerely,
Swain
E-iceblue support team
User avatar

Swain.Wang
 
Posts: 34
Joined: Thu Jun 01, 2023 3:55 am

Mon Jun 12, 2023 11:16 am

Hello,
sorry I can't download Spire.pdf 9.6 hot fix, because I have Spire Office Platinum 7.5.4 of last year.
We are going to buy Spire officer Platinum 8.6 in the next weeks. Can I download spire office platinum 7.12 using my actual license for 7.5.4, to try to resolve?
thank you,
Paola

paolagumi
 
Posts: 85
Joined: Tue Apr 21, 2015 11:32 am

Mon Jun 12, 2023 12:24 pm

Hello,
I've just tried with Spire.office platinum 7.12, the issue hasn't been solved...
I have windows 10 64 bit, .net 4.0,
I'm attaching the zipped files to union altogether, it's their union which is interrupted (sometimes),
thank you,
Paola

paolagumi
 
Posts: 85
Joined: Tue Apr 21, 2015 11:32 am

Tue Jun 13, 2023 9:16 am

Hello,

Thanks for more information.
I have tested your case with your pdf files, but I still couldn't reproduce your issue. As you mentioned before, this issue occurs randomly, so it it's difficult for us to locate the cause. Are you calling code in multithreading? Could you please provide us with a simplified project that can reproduce your issue? In addition, we have another way to merge PDF documents. Please try this way(Merge PDF Documents) to test and let us know the results. Look forward to your feedback.

Best Regards,
Swain
E-iceblue support team
User avatar

Swain.Wang
 
Posts: 34
Joined: Thu Jun 01, 2023 3:55 am

Tue Jun 13, 2023 11:05 am

Hello,
ok,
I'll try the merge method as soon as possible and let you know.
(I'm not calling the code in multithreading),
thank you and best regards,
Paola

paolagumi
 
Posts: 85
Joined: Tue Apr 21, 2015 11:32 am

Wed Jun 14, 2023 1:45 am

Hello,

Thanks for your reply.
We will look forward to your test results. If you encounter any issues during the testing process, please feel free to write back.
Wish you all the best!

Sincerely,
Swain
E-iceblue support team
User avatar

Swain.Wang
 
Posts: 34
Joined: Thu Jun 01, 2023 3:55 am

Wed Jun 14, 2023 11:31 am

Hello,
I've just tried the mergefiles command, but it gives me this error:
"the value cannot be null"
It refers to the parameter "filename".
Here is my full code:
Dim ElencoFilesDir As String()
ReDim ElencoFilesDir(99999)
Dim idxfil As Int32 = 0

For Each filettoM As System.IO.FileInfo In fInfoM

ElencoFilesDir.SetValue(filettoM.FullName, idxfil)

If Not My.Computer.FileSystem.FileExists(nomefileunico) Then
Dim documentovuoto As New PdfDocument()
documentovuoto.LoadFromFile(DirPdfSingoliData & "\" & filettoM.Name)
documentovuoto.SaveToFile(nomefileunico)
documentovuoto.Close()
documentovuoto.Dispose()
documentovuoto = Nothing
Else

' questo funziona con numero di pagine illimitate per pdf:
Dim files As String() = New String() {nomefileunico, DirPdfSingoliData & "\" & filettoM.Name}
Try
Dim docs(files.Length - 1) As PdfDocument
docs(0) = New PdfDocument(files(0))
docs(1) = New PdfDocument(files(1))
For npagina = 0 To docs(1).Pages.Count - 1
docs(0).InsertPage(docs(1), npagina)
Next

docs(0).SaveToFile(nomefileunico, Spire.Pdf.FileFormat.PDF)
docs(0).Close()
docs(0).Dispose()

docs(1).Close()
docs(1).Dispose()

docs = Nothing
files = Nothing

Catch ex As Exception
Messaggio = New DataCenter.Classi.Oggetti.Utilita.Messaggio
Messaggio.IdTipo = DataCenter.Classi.Oggetti.Utilita.Messaggio.TipoMessaggio.TMErrore
Messaggio.Testo = "Errore in scrittura pdf, il file è impegnato da altro utente o ci sono limitazioni di accesso. " & ex.Message
objLabelMessaggioErrore.Text = "Errore in scrittura pdf, il file è impegnato da altro utente o ci sono limitazioni di accesso. " & ex.Message
Messaggi.Add(Messaggio)
Messaggio = Nothing
ScritturaPdfServizioExtraGiornalieroAS400 = False
Exit Function
End Try

End If
idxfil = idxfil + 1
Next

Dim docProvaPaolaG As PdfDocumentBase = PdfDocument.MergeFiles(ElencoFilesDir)
docProvaPaolaG.Save(PercorsoOrigine & "\ProvaPaolaG.pdf", Spire.Pdf.FileFormat.PDF)


ElencoFilesDir array contains these values:

(0): "\\appnas\ufficio\Gestione PV\Servizi ExtraUrbani\2023\062023\Singoli 30062023\ServizioExtra BAR.pdf"
(1): "\\appnas\ufficio\Gestione PV\Servizi ExtraUrbani\2023\062023\Singoli 30062023\ServizioExtra BAZ.pdf"
(2): "\\appnas\ufficio\Gestione PV\Servizi ExtraUrbani\2023\062023\Singoli 30062023\ServizioExtra CAL.pdf"

best regards,
Paola

paolagumi
 
Posts: 85
Joined: Tue Apr 21, 2015 11:32 am

Thu Jun 15, 2023 9:43 am

Hello,

Thanks for your feedback.
Sorry, I still haven't reproduced the issue you mentioned on my side. Please use the following code to verify your issue directly. If your problem exists, I'm afraid we need you to provide us with a simplified project that can be run directly. Thanks in advace.
Code: Select all
Dim folderPath As String = "Singoli 30062023"
Dim fileArray() As String
fileArray = System.IO.Directory.GetFiles(folderPath, "*.*", System.IO.SearchOption.AllDirectories)
Dim doc As PdfDocumentBase = PdfDocument.MergeFiles(fileArray)
doc.Save("output.pdf", FileFormat.PDF)

Best Regards,
Swain
E-iceblue support team
User avatar

Swain.Wang
 
Posts: 34
Joined: Thu Jun 01, 2023 3:55 am

Return to Spire.PDF

cron