如何使用 Server.MapPath() 保存到子文件夹

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

我正在使用 iTextSharp 创建一个新的 PDF 并将其保存到我服务器上的一个文件夹中。 下面这行代码会将它保存到包含我的 类 的文件夹(在下图中称为 XFolder),使用 Server.MapPath():

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

我想将我的 PDF 保存在 XFolder 中的文件夹中(在 AFolder 中):

我试过:

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

但我遇到了异常:

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

"Save the PDF file into AFolder, which is a child of the current folder XFolder"怎么说?

根据 MSDN 你可以使用:

MapPath("AFolder/myFile.pdf")