0

I am creating a new PDF with iTextSharp and saving it to a folder on my server. The following line of code will save it into the folder (called XFolder in the image below) containing my classes using Server.MapPath():

Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(HttpContext.Current.Server.MapPath("myFile.pdf"), FileMode.Create)) 

I want to save my PDF in the folder that is inside XFolder (in AFolder): ![enter image description here

I have tried:

Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(HttpContext.Current.Server.MapPath("~/AFolder/myFile.pdf"), FileMode.Create))

but I get the exception:

System.IO.DirectoryNotFoundException: Could not find a part of the path.......

How do I say "Save the PDF file into AFolder, which is a child of the current folder XFolder"?

Jongware
  • 22,200
  • 8
  • 54
  • 100

1 Answers1

2

According to MSDN you can use:

MapPath("AFolder/myFile.pdf")
tezzo
  • 10,858
  • 1
  • 25
  • 48