I am one of the developer that alwasys confuse with file path that looks like <*img src=".../love/app/basic.jpg" /*>". i really do not like because it can be problematic especially if you are ASP.NET developer that uses master pages across the pages.
if you are one of those guy that always experince broken links, I have an elegant solution to this problem.
Given a virtual directory named site, which can be accessibled as http://localhost/site and you have a file which located at http://localhost/site/games/alien.jpg
to effectively locate the alien.jpg, you got to use this
In this way, you won't be confused how the file is located. ~ represents the parent virtual path.ResolveUrl("~/games/alien.jpg")
Ok, if you wish to upload the file to the server using the ResolveUrl don't give you the real path... in this case, replace the ResolveUrl method to MapPath method.
e.g:
MapPath("~/games/alien.jpg"). The file will be uploaded to the location of '~'.
Got it?
No comments:
Post a Comment