close pdf in webbrowser control

Posted on 2008-10-03
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



            WebBrowser1.Url() = New Uri("about:blank")


            For x = 0 To cont

                Call DeleteFile(drows(x).Item("id"))


            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


            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





            Dim risp As String = MsgBox("Il file non è stato trovato nel percorso corretto, vuoi eliminarlo anche dal programma?", MsgBoxStyle.YesNo)

            If risp = vbYes Then



            End If

        End If

    End Sub

Open in new window

Question by:marcocatelli
LVL 18

Accepted Solution

vbturbo earned 500 total points
ID: 22660131

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


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable  to create new object 9 41
Recommendation vb6 to or others 14 112
Open a word document 23 33
VB6 ListBox Question 4 34
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now