开发者

ASP.Net How can I upload file to virtual directory on same server as web app

开发者 https://www.devze.com 2023-02-16 13:58 出处:网络
I have a web server with a web application and a website both on it (2 seperate entities within IIS7.0). The web application needs to be able to upload files to a virtual directory created within the

I have a web server with a web application and a website both on it (2 seperate entities within IIS7.0). The web application needs to be able to upload files to a virtual directory created within the same web server and the website needs to be able to view that virtual directory to be able to开发者_C百科 allow for downloading of those files.

This sounds really easy, but I cannot figure out how to do the upload and the download.

Example:

Virtual directory = own folder file structure (does not fall within either website/webapp structure)

Website - standard user for outside users.

Webapp - authentication requierd and only used by inside users.

Webapp users upload files to virtual directory Website users download files from virtual directory (i.e. open files)

can anyone help please.


Accessing the directory:

The directory that is to contain the file will not be under the file structure of either one or the other website/app, (or maybe both if the directory is elsewhere in the filesystem). To give a website access to such a location you can create a virtual directory in the folder structure of your website which points to the location required. In IIS7 (Windows 7) the steps are:

  1. Select the website that needs the link adding
  2. Select "View Virtual Directories"
  3. Select "Add Virtual Directory"
  4. Choose an alias (something like "upload"/"download" would be good) and select the physical path of the folder
  5. You may need to tweak the "connect as" or permissions on the folder to make it writable depending on where it is

Upload:

If you use the standard file upload control you will end up with a byte array and a name of the file once post back has occured. You can write the bytearray as a file with the desired file name

Download:

Either provide a link, or use a javascript window.open to the location that the file is saved in. Note that you might need to tweak IIS MIME type settings to allow the webserver to serve the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消