I am implementing a system where the user can upload any number of documents of almost any file type to be linked to a "work item". Essentially, the user can generate a task, known as a work item, and attach any number of files to it. I've implemented the components to handle the work item itself, uploading the files, managing the files (editing and deleting), but I am running into problems viewing the files.
When the user uploads a file, the file is saved in a network folder. All users have read-access to all files in the directory. The path to the file is saved in the database, which I access through Entity Framework.
My current issue is that I can't find a generic way to open those files. I have implemented a controller to stream the file to the browser, but this only works for certain file types.
Specifically, I've tried:
Creating a hyperlink and putting the file path in the href tag, but this tries to open the file path relative to the application's location on the webserver. Basically, it appends the file path to the current URL.
Example:
href="@Path.Combine(item.PATH, item.NAME)"
Output:
href="\\server\myapp\item\3\test.jpg"
- But when I click on this anchor, it is opened relative to my current URL.
Creating a controller to stream the file via a WebClient, but this only works for specific file types.
In summary, is there a way to open any file from MVC, either through the browser or by opening it on the client computer?