Writing to a file which is already uploaded to my webspace

Soldato
Joined
18 Oct 2002
Posts
15,861
Location
NW London
Hi,

I have an asp.net web page, which needs to write to a text file, located in the same directory (up on my host's server). I am currently trying to use StreamWriter to achieve this.

I am having problems writing to this text file.

The main problem is finding the full path of the file. Is there are trick I can use, to avoid having to specify the the full path of the file (as this is what is creating a big problem)?

So, to give you an idea we have the following files:

PastMessages.ai
PrecompiledApp.config
default.aspx
web.config

default.aspx contains the program which does the file writing.

What I want to do is have the program carry out some simple operations and then to write to PastMessages.ai, every time a button is pressed. However, in order to do this, I need to know the FULL path of PastMessages.ai, which I cannot find (correctly).

Any help would be appreciated.
 
You can use Server.MapPath("<relative url>");

Where "~/" is the relative root of your site.

So, in this example, Server.MapPath("~/PastMessages.ai") will return the the full path of that file.
 
You can use Server.MapPath("<relative url>");

Where "~/" is the relative root of your site.

So, in this example, Server.MapPath("~/PastMessages.ai") will return the the full path of that file.

I was previously using: "/PastMessages.ai", but didnt think to prefix it with "~".

Thank you sah!

I shall try this out and see if this works.
 
Back
Top Bottom