Directory FileSystemInfo file and folder permissions

B

Brian Watkins

I am trying to loop through a directory and place all the folders and files
into an array. I want to store only the folders and files that the current
user has access to into the array. Below is some sample code of what I'm
doing:

Public Sub ProcessDirectory(byval strPath as string)
Dim strRootFolder As String = Server.MapPath(strPath)
Dim dir As New DirectoryInfo(strRootFolder)
Dim fsi As FileSystemInfo
For Each fsi In dir.GetFileSystemInfos()
Try
If TypeOf fsi Is FileInfo Then 'its a file
PutFileintoArray(fsi)
Else 'its a directory
Dim d As DirectoryInfo = CType( fsi, DirectoryInfo )
PutDirectoryintoArray(d.name)
ProcessDirectory(strpath & d.name & "/")
End If
Catch

End Try
Next fsi

End Sub

When the above code runs it stores all the folders and files nicely into the
array but it is not using the permissions of the client user. It only adds
the folders and files that everyone has access to. I need to run the above
code with the client users windows permissions.

In IIS Directory Security, the Anonymous access is unchecked and Integrated
Windows Authentication is checked.
In the Web.config authentication mode="Windows".

Does anyone know what I'm doing wrong here?
 
B

Brian Watkins

I found that I needed to set

<identity impersonate="true" >

in the Web.config file. Works like a charm now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top