Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2008 > Visual Basic 2008 Professionals
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 15th, 2008, 03:22 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Vista: Getfiles throws security error

Greetings,



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

    t.Start()

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

        Next

    End If

End Sub

Reply With Quote
  #2 (permalink)  
Old February 9th, 2009, 04:47 PM
Authorized User
 
Join Date: Dec 2008
Location: Keyport, NJ 07735
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
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
Reply With Quote
  #3 (permalink)  
Old February 9th, 2009, 06:00 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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.
__________________
HTH

Gonzalo


================================================== =========
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 :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:57 PM.


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