部署 .NET 应用程序
Deployment .NET App
部署应用程序时出现此错误。
找不到部分路径 'c:\windows\system32\inetsrv\~\App_Data\xxxx.pdf'。
异常详细信息:System.IO.DirectoryNotFoundException:找不到路径的一部分 'c:\windows\system32\inetsrv\~\App_Data\XXXX.pdf'。
应用程序默认方法是重定向到 pdf 文件。
这是我的代码
FileStream fs = new FileStream("~/App_Data/xxx.pdf", FileMode.Create);
Document doc = new Document(PageSize.A4, 25, 25, 30, 30);
doc.SetMargins(40f, 40f, 40f, 20f);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
请问有什么帮助吗?
谢谢,
您的 FileStream
路径文件使用 ASP.NET 带波浪号前缀的相对路径,请尝试使用 Server.MapPath
方法将其映射到正确的路径:
FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/xxx.pdf"), FileMode.Create);
如果代码存在于控制器 class 的操作方法中,只需使用 HttpContext.Current.Server.MapPath
:
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/App_Data/xxx.pdf"), FileMode.Create);
类似问题:
Read contents of a file using a relative path in a Web Application
ASP.NET C# - Save FileStream on server
部署应用程序时出现此错误。 找不到部分路径 'c:\windows\system32\inetsrv\~\App_Data\xxxx.pdf'。
异常详细信息:System.IO.DirectoryNotFoundException:找不到路径的一部分 'c:\windows\system32\inetsrv\~\App_Data\XXXX.pdf'。
应用程序默认方法是重定向到 pdf 文件。
这是我的代码
FileStream fs = new FileStream("~/App_Data/xxx.pdf", FileMode.Create);
Document doc = new Document(PageSize.A4, 25, 25, 30, 30);
doc.SetMargins(40f, 40f, 40f, 20f);
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
请问有什么帮助吗?
谢谢,
您的 FileStream
路径文件使用 ASP.NET 带波浪号前缀的相对路径,请尝试使用 Server.MapPath
方法将其映射到正确的路径:
FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/xxx.pdf"), FileMode.Create);
如果代码存在于控制器 class 的操作方法中,只需使用 HttpContext.Current.Server.MapPath
:
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/App_Data/xxx.pdf"), FileMode.Create);
类似问题:
Read contents of a file using a relative path in a Web Application
ASP.NET C# - Save FileStream on server