• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

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(Server.MapPath("/files"))
        For Each fi As System.IO.FileInfo In di.GetFiles()
            Response.Write(String.Format("<a href=""/files/{0}"">{0}</a><br />", fi.Name))
        Next
I'm using vb.net 2003.  Thanks
0
bergertime
Asked:
bergertime
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
sabeeshCommented:
You can define this path in web.config and access like

filePath = ConfigurationManager.AppSettings["FilePath"];

web.config part

<appSettings>
            <add key ="FilePath" value="C:\YourStuff\" />
    </appSettings>
0
 
hiteshgoldeneyeCommented:
Use this
Private Function Recur(ByVal strPath As String) 'set byval to desired path
Dim oDir As New System.IO.DirectoryInfo(strPath)
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).Name.ToString.SubString(oFiles(i).Name.ToString.Length-4))
Next
End Function
0
 
hiteshgoldeneyeCommented:
sorry use this
Private Function Recur(ByVal strPath As String) 'set byval to desired path
Dim oDir As New System.IO.DirectoryInfo(strPath)
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).Name.ToString)
Next
End Function
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
PaulHewsCommented:
You could simply change this line:
Dim di As New System.IO.DirectoryInfo(Server.MapPath("/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 .
0
 
bergertimeAuthor Commented:
"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

0
 
PaulHewsCommented:
>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.
0
 
bergertimeAuthor Commented:
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
0
 
PaulHewsCommented:
>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<

That's right, you don't have to recompile.  Your config file is just a text file that is read by your application.  
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now