Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi,
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
C#
/*launch File*/   
System.Diagnostics.Process.Start(targetPath + fileName);

full path is targetpath+fileName.

Please help me to find a solution.
Posted
Comments
Sergey Alexandrovich Kryukov 24-Jun-15 0:52am    
Where do you try to download anything? How can it possibly be related to ASP.NET and MVC?
—SA
Member 11670657 24-Jun-15 0:57am    
yep, really download or open the file. And also, open through the browser window is also ok.
Sergey Alexandrovich Kryukov 24-Jun-15 1:01am    
Where? :-)
Okay, I got it. No, you are not downloading anything. Your question simply makes no sense as formulated.
—SA
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

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.

C#
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));
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900