Reputation: 43
I want to make an application that exports a PDF file whose content comes from the database. This my controller controller:
public ActionResult DownloadTopic(int Id)
{
var Topic = DB.Topics.singleordefualt(o=>o.id == Id);
return File(Topic.Body, "application/pdf");
}
But I get this error "Could not find a part of the path 'C:\Users\katkooot\Desktop\project\Discussion\MvcApplication22\MvcApplication22\Topic\DownloadTopic"
.
Upvotes: 2
Views: 1366
Reputation: 3532
You didn't provide enough details, it would greatly help if you would answer what others asked - what is the type of Topic
.
But based on this as a wild guess - try to return FileContent
instead of File
.
Upvotes: 0
Reputation: 9296
You need to convert the result into PDF. You cannot just take the result that is some .NET class, interface or custom user object and return it as PDF just like that. You should use libraries like iTextSharp to enumerate through your results and return a PDF. Here is a tutorial by Ozzie Perez on how to open a document, write a PDF table and return it to the user Creating a PDF with iTextSharp and ASP.Net MVC 2
Upvotes: 1