Link to home
Start Free TrialLog in
Avatar of mainrotor
mainrotor

asked on

I need help with a link in my MVC.Net application with C#.Net code-behind

Hi Experts,
I have an MVC.Net application that uses C#.Net code behind.
In my views I use a Kendo UI grid.  One of the columns in the grid is a link.

When the user clicks on the link it should open a .pdf file.  So we need to pass the file path and the file name.
How can I do this?

Thank you,
mrotor
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

The simplest thing to do would be to make the link a direct link to the PDF (e.g. https://mysite.com/thepath/thefile.pdf.

However, direct linking to files on your server can be a bit dangerous in cases where the user should only be able to access certain files (e.g. files pertaining only to his or her company or personal business).

I would recommend not including the path on the request as that exposes the structure of your file storage as well. Instead, come up with a convention-based approach for storing the files and only provide the file name to the front-end. Then you simply create a controller action that returns a File.

public ActionResult GetPdf(string fileName)
{
    // figure out path to file using some convention
    return File(Path.Combine(path, fileName);
}

Open in new window

Avatar of mainrotor
mainrotor

ASKER

Craig,
Thanks for the reply.  I have to use the URL because the .pdf files are actually stored at a vendors site.  Not on our on server.
So we pass the url and append the file name to the url.

I will post a sample of the how it's currently being done in a non-web app.

Thanks,
mrotor
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.