【问题标题】:How to save to a child folder using Server.MapPath()如何使用 Server.MapPath() 保存到子文件夹
【发布时间】:2015-10-08 08:21:56
【问题描述】:

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

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:找不到一部分 路径.......

“将 PDF 文件保存到 AFolder,它是当前文件夹 XFolder 的子文件夹”怎么说?

【问题讨论】:

  • 你试过“AFolder/myFile.pdf”吗?

标签: vb.net server.mappath


【解决方案1】:

根据MSDN可以使用:

MapPath("AFolder/myFile.pdf")

【讨论】:

  • 谢谢@tezzo,一个简单的问题,但我真的需要额外的帮助:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-19
  • 2022-01-06
  • 1970-01-01
相关资源
最近更新 更多