Pages

Thursday, March 15, 2012

Get the path of your Web application using PhysicalApplicationPath (ASP.NET)

If you need to access a file or image from your ASP.NET Web application, store it in your project directory and use the PhysicalApplicationPath method of the Request object to retrieve it when your page loads or posts to the server.

PhysicalApplicationPath returns the full path name, including the last backslash. So you might receive something like this:

C:\inetpub\wwwroot\WebApplication1

So, if you stored an XML file in the WebApplication1 directory, you might access it using the following code:

Dim myfile As string
myfile = Request.PhysicalApplicationPath & "DataFile.xml")


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.