Jana Pasch Jana Pasch - 1 year ago 141
C# Question

Getting the error message: “Could not find a part of the path"

I create a Folder (File) and i want that after i click the button (btnGenerate_Click) it should create a pdf file and save it into the Folder, named "File". But i constantly getting the error message: "Could not find a part of the path "C:\User\VS\Intra\Intra.Admin\File\" But the Location of the path is correct....

protected void btnGenerate_Click(object sender, EventArgs e)
string FilePath = MapPath("~/File/"); //here!

iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 20f, 20f, 20f, 20f);
PdfWriter.GetInstance(pdfDoc, new FileStream(FilePath, FileMode.Create));
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.AllowPaging = false;
GridView1.HeaderRow.Cells[1].Text = "Message";
GridView1.HeaderRow.Font.Bold = true;

StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);


Response.ContentType = "Application/pdf";


Answer Source

FilePath is a directory. You should append a filename, so something like this:

string FilePath = MapPath("~/File/" + fileName);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download