0

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 ?

1
  • I don't think you can. You can access with absolute path. Commented Mar 22, 2014 at 16:46

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for response, but it seems doesn't work with ` ImageResizer`,stackoverflow.com/questions/22586936/…; Could you please guide me ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.