accessing directory over network

RTT

Active member
Joined
Mar 16, 2005
Messages
26
Programming Experience
Beginner
Working with folders and files in VB.Net

i want to create an application to search files on a server. But i don't
know where to start. is there anyone who has code that he or she is willing
to share? I'm searching for code to search files with a specific extension.

I think to main problem is that the directory's i want to search are on an
computer in the network and i should reach them as
\\computername\directory\.... also i should be able to read those
directory's as a specific user. So how can i read in a directory over the
network while authentication with a specific username?

kind regards
 
Last edited:

RTT

Active member
Joined
Mar 16, 2005
Messages
26
Programming Experience
Beginner
I can access a directory with this code.

VB.NET:
 [size=2][color=#0000ff]
Dim[/color][/size][size=2] strPath [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String[/color][/size][size=2] = "[url="file://\\bexxghe01fp0001\Users\josgijsens"]\\be0001\Users\josgijsens[/url]"

[/size][size=2][color=#008000]'Dim strPath As String = "c:\"

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] strFile, strDir [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2][/size][size=2][color=#008000]For Each strDir In Directory.GetDirectories(strPath)

[/color][/size][size=2][/size][size=2][color=#008000] RichTextBox1.AppendText(Path.GetFileName(strDir) & vbCrLf)

[/color][/size][size=2][/size][size=2][color=#008000]Next

[/color][/size][size=2][/size][size=2][color=#0000ff]For[/color][/size][size=2] [/size][size=2][color=#0000ff]Each[/color][/size][size=2] strFile [/size][size=2][color=#0000ff]In[/color][/size][size=2] Directory.GetFiles(strPath)

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

[/size][size=2][color=#0000ff]Next

[/color][/size]

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 is. 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?

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
 
Top Bottom