bergertime
asked on
vb.net 2003 get files from folder on c:
I'm using this code to get files from a folder on a virtual directory, how would I change it to get files from c:\mystuff\files
Dim di As New System.IO.DirectoryInfo(Se rver.MapPa th("/files "))
For Each fi As System.IO.FileInfo In di.GetFiles()
Response.Write(String.Form at("<a href=""/files/{0}"">{0}</a ><br />", fi.Name))
Next
I'm using vb.net 2003. Thanks
Dim di As New System.IO.DirectoryInfo(Se
For Each fi As System.IO.FileInfo In di.GetFiles()
Response.Write(String.Form
Next
I'm using vb.net 2003. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry use this
Private Function Recur(ByVal strPath As String) 'set byval to desired path
Dim oDir As New System.IO.DirectoryInfo(st rPath)
Dim oSubDir() As System.IO.DirectoryInfo
Dim oFiles() As System.IO.FileInfo
Dim i As Int32
oFiles = oDir.GetFiles
For i = 0 To oFiles.Length - 1
Response.Write(oFiles(i).N ame.ToStri ng)
Next
End Function
Private Function Recur(ByVal strPath As String) 'set byval to desired path
Dim oDir As New System.IO.DirectoryInfo(st
Dim oSubDir() As System.IO.DirectoryInfo
Dim oFiles() As System.IO.FileInfo
Dim i As Int32
oFiles = oDir.GetFiles
For i = 0 To oFiles.Length - 1
Response.Write(oFiles(i).N
Next
End Function
You could simply change this line:
Dim di As New System.IO.DirectoryInfo(Se rver.MapPa th("/files "))
To
Dim di As New System.IO.DirectoryInfo("C :\MyStuff\ files"))
But I recommend that you follow the directions given by sabeesh for adding it to your config rather than hard coding it.
Note that you may have to add permissions to folder for the ASP.NET worker process user. It's usually ASPNET, but you can find the name using Environment.UserName .
Dim di As New System.IO.DirectoryInfo(Se
To
Dim di As New System.IO.DirectoryInfo("C
But I recommend that you follow the directions given by sabeesh for adding it to your config rather than hard coding it.
Note that you may have to add permissions to folder for the ASP.NET worker process user. It's usually ASPNET, but you can find the name using Environment.UserName .
ASKER
"But I recommend that you follow the directions given by sabeesh for adding it to your config rather than hard coding it."
As I was typing in my question, it dawned on me to try your suggestion, and it works fine......I'm just wondering why you would recommend it that way? Thanks
As I was typing in my question, it dawned on me to try your suggestion, and it works fine......I'm just wondering why you would recommend it that way? Thanks
>I'm just wondering why you would recommend it that way? Thanks
Well, just because something works doesn't mean there isn't a better way to do it. If you were deploying this application to some other environment, and you had to point to a different folder, then if you had hard coded the path, you would have to change the source code, recompile and deploy the new version. Then the source would no longer be compatible with your development environment. So as a general rule, it is far better to not hard code path information in your application, but retrieve it either as a relative path (using Server.MapPath for ASP.NET) or as a setting in a config file.
Well, just because something works doesn't mean there isn't a better way to do it. If you were deploying this application to some other environment, and you had to point to a different folder, then if you had hard coded the path, you would have to change the source code, recompile and deploy the new version. Then the source would no longer be compatible with your development environment. So as a general rule, it is far better to not hard code path information in your application, but retrieve it either as a relative path (using Server.MapPath for ASP.NET) or as a setting in a config file.
ASKER
Oh, so just to help me understand. If I make changes to my config file, I don't have to recompile? I've always recomplied after making changes to my config file. Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Function Recur(ByVal strPath As String) 'set byval to desired path
Dim oDir As New System.IO.DirectoryInfo(st
Dim oSubDir() As System.IO.DirectoryInfo
Dim oFiles() As System.IO.FileInfo
Dim i As Int32
oFiles = oDir.GetFiles
For i = 0 To oFiles.Length - 1
Response.Write(oFiles(i).N
Next
End Function