Instead of saving pdf file, showing directory listing

Viewed 82

I'm using simple code in MVC controller to save pdf file on server with iTextSharp:

var reportName = "reports/" + "report1.pdf";
var output = new FileStream(Server.MapPath(reportName), FileMode.Create, FileAccess.Write, FileShare.None);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
document.Add(new Paragraph("Hello World"));
document.Close();
return View();

But it was giving error

A default document for the desired URL is not configured and folder browsing is not enabled on the server.

Then I set this code in web.config

<directoryBrowse enabled="true" />

Now instead of saving pdf file, browser showing directory listing.

1 Answers

put a dummy default.aspx file in the root folder this will not be used when MVC is working, but can get rid of this problem.

Related