save file to virtual directory

淺唱寂寞╮ 提交于 2019-11-30 17:41:28

问题


Hi I am unsure how to do this, I am using shared hosting. I have a virtual directory at http://www.example.com/images. This directory is actually a folder on the server assets/images whereas my site is at /httpdocs (httpdocs and assets folder are at the same level).

How can I save files to this folder and then access using eg /images/foo.jpg?

httpdocs/
--web.config
--default.aspx
--etc

assets/
--images/
----foo.jpg


回答1:


You can save files normally (using FileStreams or other things).
Call Server.MapPath("~/httpdocs") to get the path on disk.




回答2:


The simplest way is to create a virtual directory in the IIS Manager so that /images actually points to assets\images (you said you already have a virtual directory on it, so this may already be done). To save things there, you use Server.MapPath("~/images") as SLaks mentioned. Server.MapPath gives you the physical location and you can save to it the way you'd save a file normally.

Exactly how you save it depends on how the person is uploading it. Are you using a form where someone picks a file and then submits it on a web page? If you are, this link will help you with the saving part.

Good luck. :)



来源:https://stackoverflow.com/questions/5369055/save-file-to-virtual-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!