Click here to Skip to main content
13,800,409 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
I have a action to download a PDF files from server. Any way at the local host it works correctly. but after host, it does not work correctly. any way after that i search over the internet, 6 hours googled. but no answer yet.

At the local host work using this code segment
/*launch File*/   
System.Diagnostics.Process.Start(targetPath + fileName);

full path is targetpath+fileName.

Please help me to find a solution.
Posted 23-Jun-15 19:32pm
Where do you try to download anything? How can it possibly be related to ASP.NET and MVC?
Member 11670657 24-Jun-15 0:57am
yep, really download or open the file. And also, open through the browser window is also ok.
Where? :-)
Okay, I got it. No, you are not downloading anything. Your question simply makes no sense as formulated.
Sinisa Hajnal 24-Jun-15 1:54am
What is your target path? Does it exist on the server? Can application access it under default rights (it needs read/write)? Are you trying for application path (relative or absolute i.e. www.yourdomain.ccc/myfiles) or server file system path (i.e. D:\mywebapp\myfiles)?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Indeed the each gentlemen's comments are correct. Process.start from the system diagnostics libary is the console or client way to open a file or start a process(exe, bat file), that doesn't work on a web server because people browsing to your site aren't on the web server. It may work on localhost because localhost IS the computer you are on. If you are truly writing an MVC WEB app and not a client app. You need to make a method in your controller that returns a fileresult and call that from a view action.

public FileResult DownloadFile(){
     fullpath = Server.MapPath("relative path of where file is") + filename;
     return File(fullpath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(fullpath));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.181214.1 | Last Updated 25 Jun 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100