vb.netserver.mappath

How to save to a child folder using Server.MapPath()


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"?


Solution

  • According to MSDN you can use:

    MapPath("AFolder/myFile.pdf")