Ted pottel
Ted pottel

Reputation: 6983

Cannot load file in VB.NET from root directory

I just made my first .net website. I'm trying to use the following line of code to load a file from the current directory ( same diredtory all the web files are in). I get a error saying file does not exist

  InstallFormTemp = My.Computer.FileSystem.ReadAllText("installerform.html")

I copied the file to my c drive and chnage the line to

 InstallFormTemp = My.Computer.FileSystem.ReadAllText("c:\installerform.html")

it worked, but now my site has to run a godaddy's webserver, so I cannot save stuff in the c drive, just my web directory.

How can I get My.Computer.FileSystem.ReadAllText to read files from the websites current directory????

Upvotes: 1

Views: 550

Answers (2)

to StackOverflow
to StackOverflow

Reputation: 124696

There are several ways, one of which is

System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "installerform.html")

Upvotes: 1

Ian Gilroy
Ian Gilroy

Reputation: 2041

There are a few methods which can help you out here - MapPath() and/or PhysicalPath() should be useful in this situation. This page provides an overview: http://msdn.microsoft.com/en-us/library/ms178116.aspx

Upvotes: 2

Related Questions