Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi to all,

 

i have searched the forum but did not find what i'm looking for. I'm new in ASP.NET so i need sime help here plz.

 

What i what is to browse directories and not files. In html the <input type="file"> searches a specific file but what i want is to select a directory.

 

I'm using vb.net so if you could give a help i would aprecciate.

 

thx to all

Posted

I'm programming ASP.NET using VB and i need to browse for directories. I know that html is not the solucoes i only gave it as an example of file browse.

 

does anyone know how to browse for directories allowing to choose one in asp.net?

  • Administrators
Posted

If you are using ASP.Net the client is still only recieving HTML, and as such is limited to the standard HTML controls.

Failing that you would need to investigate some other client side technology such as Java and provide your own custom UI.

 

It may help if you gave more details about why you need to do this as there could be an alternate solution to your problem.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Well what i want seems simple enough but i have some problems with directory browsing. So its this:

 

The administrator of the aplication can upload images to the database. There will be a directory (not always the same) where the images will be put. The admin them browses to that directory and selects it. By doing that it will upload all images in that directory to the database. I cannot consider doing one by one because there could be alot of images.

 

So i need to pick the directory and browse for all the files and upload them to the database.

 

Any good ideas how to do this?

Posted

actually a solved the problem! i can browse througth directories and get the files that existe currenttly there. And i can event open the file if i want.

 

you you want the solution just let me know and i'll post it here

Posted

well...it's quite simple.

 

Bare in mind that this browses througth the server's hard disk not the client's

 

here it is :)

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Browse()

End Sub

 

 

In this sub "ServerDirectory" is a constant from where tou want to start. you can get all drives with

 

drives = System.IO.Directory.GetLogicalDrives()

 

Private Sub Browse()

Try

Dim dir As DirectoryInfo = New DirectoryInfo(ServerDirectory)

Dim fsi As FileSystemInfo

 

For Each fsi In dir.GetFileSystemInfos()

Try

'This means it is'nt a file thus a directory

If Not TypeOf fsi Is FileInfo Then

Dim d As DirectoryInfo = CType(fsi, DirectoryInfo)

Dim dirName As String = Path.GetFullPath(d.FullName.ToString)

response.write("dirName")

If (d.GetDirectories().Length > 0) Then

LoadSubDirectory(dirName)

Else

response.write("dirName")

End If

End If

Catch Ex As Exception

End Try

Next fsi

 

Catch Ex As Exception

Response.Write(Ex.ToString())

Response.End()

End Try

End Sub

 

then recursevly i get all subdirectories

 

Private Sub LoadSubDirectory(ByVal thisDir, ByVal contadorPai, ByRef _menuHtml)

Try

 

Dim dir As DirectoryInfo = New DirectoryInfo(thisDir)

Dim fsi As FileSystemInfo

 

For Each fsi In dir.GetFileSystemInfos()

Try

If Not TypeOf fsi Is FileInfo Then

Dim d As DirectoryInfo = CType(fsi, DirectoryInfo)

Dim dirName As String = Path.GetFullPath

response.write(dirName)

If (d.GetDirectories().Length > 0) Then

LoadSubDirectory(dirName, strMenuNome, _menuHtml)

End If

 

End If

Catch E As Exception

 

End Try

Next fsi

 

Catch E As Exception

Response.Write(E.ToString())

Response.End()

End Try

End Sub

 

 

hope it helped :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...