Url path and absolute path

There are quiet few cases that we need to find the file absolute path on the storage and the url path which can be referenced. The following is the the summary.

The test.pdf file is located at “c:\Inetpub\VirtualWebsite\Subfolderpath\test.pdf”
The url should be: http://servername/VirtualWebsite/Subfolderpath/test.pdf

 Dim strPathAndQuery As String = HttpContext.Current.Request.Url.PathAndQuery

 Dim strUrl As String = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/")

 'http:// or https://
 Dim protocolpath As String = HttpContext.Current.Request.Url.Scheme + "://"

 'servername or domainname
 Dim apphost As String = HttpContext.Current.Request.Url.Authority

 Dim apppath As String = HttpContext.Current.Request.ApplicationPath

 'the whold url path
 pdffilepath = protocolpath + apphost + apppath + "subfolderpath/test.pdf"  

 Server.MapPath("~\downloads\") + filename


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s