나는 프로그램에 grab PDF 파일을 가지고 병합 한 다음 원래의 병합되지 않은 파일을 휴지통으로 삭제합니다.내 프로그램이 여전히 열려 있기 때문에 파일을 삭제할 수 없습니다.
나는 Syncfusion PDF 도구를 이용하기 위해 프로그램을 수정했으며, 파일을 삭제하려고 할 때까지 대부분 원활하게 진행되었습니다.
경고 팝업은 내 프로그램이 파일을 열었 음을 알려주지 만 프로그램에서 어디서 열려 있는지 또는 어떻게 찾을 수 있는지 잘 모르겠습니다.
여기에 함수의 :
Function MergePDFSync(ByVal Path As String, ByVal SavePath As String, ByVal outFileName As String, ByVal DeleteOriginal As Boolean) As String
On Error GoTo sError
Dim CreateDate As Date = Now
Dim finalFileName As String = ""
Dim dInfo As New DirectoryInfo(Path)
If dInfo.GetFiles("*.pdf").Length > 0 Then
Dim doc As New Syncfusion.Pdf.PdfDocument
Dim ldoc As Syncfusion.Pdf.Parsing.PdfLoadedDocument
Dim file As String
For Each f As FileInfo In dInfo.GetFiles("*.pdf")
ldoc = New Syncfusion.Pdf.Parsing.PdfLoadedDocument(f.OpenRead)
Syncfusion.Pdf.PdfDocument.Merge(doc, ldoc)
ldoc.Close()
doc.DisposeOnClose(ldoc)
Next
ldoc = Nothing
finalFileName = Format(CreateDate, "M-d-yy-HHmmss-") & outFileName
doc.Save(Path & "\" & finalFileName)
doc.Close()
doc = Nothing
dInfo = Nothing
If DeleteOriginal Then ' delete origional files
dInfo = New DirectoryInfo(Path)
For Each f As FileInfo In dInfo.GetFiles("*.pdf") 'For i As Integer = 0 To strFiles.Length - 1 ' run through all the files in the directory
Console.WriteLine("MergePDF2 10.1 : " & f.Name & " = " & finalFileName)
If Not f.Name = finalFileName Then
Console.WriteLine("MergePDF2 10.2 : Delete " & f.FullName)
My.Computer.FileSystem.DeleteFile(f.FullName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
End If
Next
End If
End If
Return finalFileName
Exit Function
sError:
ReportError("MergePDF2 " & Path & " " & Err.Description)
Console.WriteLine("MergePDF2 " & Path & " " & ErrorToString())
End Function
의 중복 가능성 [C# 파일 예외 : 다른 프로세스에서 사용하고 있기 때문에 파일을 액세스 할 수 없습니다] (http://stackoverflow.com/questions/2701685/c-sharp-file-exception-cannot-access-the-file-because-it-is-being-used-by-anoth) 및 약 12 개 (공개 링크 I p 그 오른쪽에있는 "관련"질문의 긴 목록을 참조하십시오). 이 사이트에서 귀하가받는 오류 메시지를 찾으십시오. 이전에 질문에 대한 답변을 받았을 가능성이 매우 높습니다. 그 중 하나가 귀하를 대신하여 답변을 드릴 수 있습니다. 행운을 빕니다. –
팁 켄 주셔서 감사합니다. 단, 먼저 모든 것을 시도했습니다. 이 문제는 분명히 Syncfusion PDFLoadedDocument에서 .Close가 작동하는 방식과 관련이 있습니다. 아래 the_lotus의 유용한 답변을 참조하십시오. – AndyD273