We help IT Professionals succeed at work.

What does Request.MapPath() do and how does it work?

353 Views
Last Modified: 2012-05-10
I want to access a file that's in a folder for the default Physical Path.  So the following code works:

             String outPutPath = Path.GetDirectoryName(Request.PhysicalPath) + "\\output";
             StreamWriter w = File.AppendText(outPutPath + "\\xmleventsincall.txt");

Is there a nicer way of doing this using MapPath()?

Thanks,
newbieweb
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
above not worked?
curiouswebsterSoftware Engineer

Author

Commented:
Yes, but what is keeping track of the location of "Hello.aspx"?  And what if there are two copies of that file in different directories?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
curiouswebsterSoftware Engineer

Author

Commented:
so does that mean IIS does not allow you to have the same file in two subfolders?
curiouswebsterSoftware Engineer

Author

Commented:
In your example, Hello.aspx is located in three folders.  I don't see how it can tell you the path in that case.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
curiouswebsterSoftware Engineer

Author

Commented:
Thanks.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.