Question

We have a folder for uploading in D:\Uploaded-Files.
There are several applications that using the uploaded files.
We're gonna add a web application in D:\Web-Application\ with asp.net and MVC 5
Can we use the uploaded files from D:\Uploaded-Files in MVC application with relative addresses ?
If so, how we can get the relative addresses ?
Edit:
If we can't do it, What your idea is to access that files from an asp.net mvc application ?

Was it helpful?

Solution

Can we use the uploaded files from D:\Uploaded-Files in MVC application with relative addresses ?

No.

If we can't do it, What your idea is to access that files from an asp.net mvc application ?

Either by using the absolute address to them or if you intend to stream them to the client you will need a server side endpoint (an MVC controller) that will use the absolute address to get the file and return it as a FileResult to the client.

For example:

public ActionResult GetFile(string filename)
{
    string actualFile = Path.Combine("D:\Uploaded-Files", filename);
    return File(actualFile, "application/octet-stream");
}

Obviously that's more than an oversimplified example without any validation. You should make sure that the client hasn't actually requested some file outside of this location and validate the filename parameter. You might also need to adjust the Content-Type.

Now a client could access the file like this:

http://yourapp.com/yourcontroller/getfile?filename=foobar.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top