Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

close pdf in webbrowser control

Posted on 2008-10-03
3
Medium Priority
?
2,322 Views
Last Modified: 2013-12-26
I have a windows form application that I use to scan pdf and jpg documents. In the form I placed a webbrowser control to preview the scanned files.
All the file paths are displayed in a listbox and when the listindex change the webbrowser navigate to the file showing it.
Sometimes may happen that the scan isn't good or something like that so I need to delete the file, but when I select the file to delete it's opened in the webbrowser. I have no problem with jpeg, but with pdf it throws an exception telling that is impossible to delete the file because it's opened in another application.
I could kill the acrobat process but it's not the solution I want.
I tried to make the webbrowser navigate to about:blank and to dispose the webbrowser but with no luck.
Plus when I shut down the computer it always tells me that there is a document opened in acrobat and ask me if I want to close it. I think is related to my application.
Any help is appreciated
Private Sub cmsScanDeleteFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmsScanDeleteFile.Click
        Dim text As String = ""
        Select Case lstScan.SelectedItems.Count
            Case 1
                testo = "Are you sure you want to delete the selected file?"
            Case Is > 1
                testo = "Are you sure you want to delete " & lstScansioni.SelectedItems.Count & " selected files?"
        End Select
        Dim risp As String = MsgBox(text, MsgBoxStyle.YesNo)
        If risp = vbYes Then
 
            Dim cont As Integer = lstScan.SelectedItems.Count - 1
            Dim drows(cont) As DataRowView
            Dim x As Integer = 0
            For Each dr As DataRowView In lstScan.SelectedItems
                drows(x) = dr
                x = x + 1
            Next
            WebBrowser1.Stop()
            WebBrowser1.Url() = New Uri("about:blank")
            WebBrowser1.Dispose()
            For x = 0 To cont
                Call DeleteFile(drows(x).Item("id"))
            Next
            Call Save()
        End If
    End Sub
 
    Private Sub EliminaFile(ByVal id As Integer)
        Dim rf As dsat.AttivazioniScansioniRow = Me.Dsat.AttivazioniScansioni.FindByid(id)
        Dim file As String = ""
        If rf.Locale = True Then
            file = My.Settings.PercorsoLocaleAttivazioniWind & "\" & rf.NomeFile & rf.Estensione
        Else
            file = My.Settings.PercorsoAttivazioni & "\" & rf.PercorsoRelativo & "\" & rf.NomeFile & rf.Estensione
        End If
        Dim psi As New System.Diagnostics.ProcessStartInfo()
        psi.UseShellExecute = True
        psi.FileName = file
        If System.IO.File.Exists(psi.FileName) = True Then
            System.IO.File.Delete(file)
            rf.Delete()
            Me.AttivazioniScansioniTA.Update(Dsat.AttivazioniScansioni)
        Else
            Dim risp As String = MsgBox("Il file non è stato trovato nel percorso corretto, vuoi eliminarlo anche dal programma?", MsgBoxStyle.YesNo)
            If risp = vbYes Then
                rf.Delete()
                Me.AttivazioniScansioniTA.Update(Dsat.AttivazioniScansioni)
            End If
        End If
    End Sub

Open in new window

0
Comment
Question by:marcocatelli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
vbturbo earned 2000 total points
ID: 22660131
Hi

i dont if this also works for webbrowser but its worth checking out


http://69.10.233.10/KB/cpp/ReaderWrapper.aspx

vbturbo
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question