NealR
NealR

Reputation: 10709

Open file from ASP MVC controller

On our ASP MVC view we have links to files on our LAN. In IE this works fine, however in Chrome you can click on the link all day and nothing will happen. We're a Microsoft shop, so it seems like some of the Office documents don't play nice with Google's browser.

As a work-around I simply want to create a controller method that will take the location of the file, passed in as a parameter from an Html.ActionLink, and open it. This is my first attmept:

    public void OpenAttachment(string location)
    {
        Process proc = new Process();
        proc.StartInfo = new ProcessStartInfo(location);
        proc.Start();
    }

This will open the file just file, however the web page then goes completely blank as the browser appears to attempt to navigate to the file's location (the LAN address appears in the navigation window).

Does anyone know of either a better method of achieving this or what I need to do to tweak the method I currently have?

Upvotes: 0

Views: 3505

Answers (2)

anthr
anthr

Reputation: 719

Not entirely sure if this is what you're looking for but have you tried a FileResult?

public FileResult OpenAttachment(string location)
{
    return File(location, "Application/{YOURTYPEHERE}");
}

Upvotes: 1

NealR
NealR

Reputation: 10709

Simply added a target = "_blank" attribute to the link and used this as a work-around. Would prefer a more elegant solution, however, if one is out there.

Upvotes: 0

Related Questions