Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Professionals
Visual Basic 2008 Professionals For advanced Visual Basic coders working in version 2008. Beginning-level questions will be redirected to other forums,
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 15th, 2008, 03:22 PM
Authorized User
Join Date: Jul 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Vista: Getfiles throws security error


I wrote a multi-threaded program that allows a user to click on a folder and then get all pdf files in the folder and all subfolders under that folder. I then loop through the pdf files and get the number of pages each has.

It works fine except, on Vista machines. If I click on a user folder in My Documents, I get an exception that says "Access to path c:\Users\Username\Templates" is denied.

I can't elevate the request execution level because the program uses Click Once.

I need to be able to loop through all folders, including the special ones.

If I can't do that, then I would like the program to continue processing the rest of the folders that it is allowed to access. Then I can create an error log with the names of the folders that refuse access.

I have included a simplified version of the code below:

'This sub fires when the user clicks the Start button. It puts their path into the variable strPath

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ' First create a FolderBrowserDialog object

    Dim FolderBrowserDialog1 As New FolderBrowserDialog

    ' Then use the following code to create the Dialog window

    ' Change the .SelectedPath property to the default location

    With FolderBrowserDialog1

        .ShowNewFolderButton = False

        .RootFolder = Environment.SpecialFolder.Desktop

        ' Prompt the user with a custom message."

        .Description = "Select the source directory"

        If .ShowDialog = DialogResult.OK Then

            strpath = .SelectedPath

            ProcessAllDirectories(strpath, objArrayList) ' These parameters are global

        End If

    End With

End Sub

ProcessAllDirectories(strpath, objArrayList)

Public Sub ProcessAllDirectories(ByVal strPath As String, ByRef objArrayList As ArrayList)

    objDirectoryInfo = New DirectoryInfo(strPath)

    t = New Threading.Thread(AddressOf ProcessDirectory)

    t.IsBackground = True


End Sub

Public Sub ProcessDirectory()

    Dim objFiles As FileInfo()

    Dim objFileInfo As FileInfo

    If objDirectoryInfo.GetFiles().Length > 0 Then

        objFiles = objDirectoryInfo.GetFiles("*.pdf", SearchOption.AllDirectories) ' This line throws the exception

        For Each objFileInfo In objFiles

            'Do processing and counting here


    End If

End Sub

Old February 9th, 2009, 04:47 PM
Authorized User
Join Date: Dec 2008
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts

Originally Posted by sigilaea View Post
If I can't do that, then I would like the program to continue processing the rest
On Error Resume Next
Old February 9th, 2009, 06:00 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

Please please please don't use on error resume next.. Patrick that's a vb 6 (and early) statement.
In vb.net, you can use a try.. catch statement to get the exception you need. Even if you don't do anything with it, you can continue from them.
Since you are having this problem, the best you can do is loop manually through all the folder to skip the ones you have problems with.


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
================================================== =========
I know that CVS was evil, and now i got the
================================================== =========

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista - IIS Config Error tracey07 ASP.NET 2.0 Basics 1 July 26th, 2007 03:02 AM
column name starts with a number. c# throws error. jaikanth_n ADO.NET 0 March 18th, 2006 01:44 PM
System.Security.SecurityException: Security error coolcatjk Pro VB.NET 2002/2003 4 March 2nd, 2006 06:00 PM
UPDATE query throws error in selective MSI tables eelisMX General .NET 0 July 14th, 2005 06:29 AM
Transformer.transform throws DOM006 error saladin XML 0 October 13th, 2004 08:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.