Working with files and folders

R

RTT

I can access a directory with this code in a windows form.



Code:
Dim strPath As String = "\\be0001\Users\josgijsens"

'Dim strPath As String = "c:\"

Dim strFile, strDir As String

For Each strDir In Directory.GetDirectories(strPath)

RichTextBox1.AppendText(Path.GetFileName(strDir) & vbCrLf)

Next

For Each strFile In Directory.GetFiles(strPath)

RichTextBox1.AppendText(Path.GetFileName(strFile).ToString & vbCrLf)

Next



with this code i can read the directories and files on my harddisks or on an
network directory "\\be0001\Users\josgijsens".



My current problem is that i'm the user with rights on
"\\be0001\Users\josgijsens" but if i want to view an other folder
"\\be0001\Users\markwouters" i don't have the rights to do this. I should be
able to acces the folder as a different user. so before i try to access it i
should somehow make sure that i access it not as the user that run the code
but as a user given in codebased with rights to all folders. is that
possible?



in a web application it is possible to impersonate a user so the page
doesn't run as the default ASP.NET user. Is it possible to do the same with
a webform. i think the code runs under the default windows user, right? so
is their a way to run code as a different user like with web applications?



second question. you can search a folder with GetFiles(strPath, "*.mp3") but
that will only search in de current path and not in the subfolders. is there
a way to search a complete map including subfolder? of will i have to write
my recursive method myself?



thxs
 
C

Crouchie1998

Lookup FileIOPermissions in the System.Security.Permissions namespace

Crouchie1998
BA (HONS) MCP MCSE
 

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

Top