简体   繁体   English

资源嵌入asp.net

[英]resource embedding in asp.net

I have a project which needs to generate PDF documents. 我有一个需要生成PDF文档的项目。 I am using iTextSharp. 我正在使用iTextSharp。 I have a pdf which needs to be read and then appended to. 我有一个pdf文件,需要阅读然后附加。

To read the pdf document, I'm using PdfReader(), which accepts many forms, but I can't figure out how to reference a pdf in my webapplication to PdfReader. 要阅读pdf文档,我使用PdfReader(),它接受许多形式,但是我不知道如何在Web应用程序中将pdf引用到PdfReader。

My host does not allow Binary Serialization (apparently that's bad), so I don't think I can load from an embedded resource. 我的主机不允许二进制序列化(这很不好),所以我认为我无法从嵌入式资源加载。 I've tried just using PdfReader("report.pdf"), but it keeps throwing an exception telling me that the file isn't found. 我已经尝试过仅使用PdfReader(“ report.pdf”),但是它一直抛出异常,告诉我找不到该文件。 I've tried putting the file in the bin directory, root directory, in the same directory as the class, but this still doesn't work. 我尝试将文件放在与类相同的目录中的bin目录,根目录中,但这仍然行不通。

It works if I use a fully qualified path to the pdf document, but I can't use that when I upload it to my hosting provider. 如果我使用pdf文档的标准路径,则此方法有效,但将其上载到托管服务提供商时无法使用它。

Does anyone have any suggestions on how I should do this? 有人对我应该如何做有任何建议吗?

Thanks 谢谢

It works if I used a fully qualified path to the pdf document, but I can't use that when I upload it to my hosting provider. 如果我使用了pdf文档的完全限定路径,则该方法有效,但是当我将其上传到托管服务提供商时,无法使用该路径。

You should still be able to get the fully-qualified path to your application via Request.PhysicalApplicationPath (which should still be available, even in medium trust). 您仍然应该能够通过Request.PhysicalApplicationPath获取到应用程序的标准路径(即使处于中等信任状态,该路径仍然可用)。

In addition, embedded resources should still work as well, since they don't actually involve binary serialisation. 另外,由于嵌入式资源实际上并不涉及二进制序列化,因此它们也应该也能正常工作。 You should be able to copy the embedded resource to a temporary file and then pass that file to PdfReader . 您应该能够将嵌入的资源复制到一个临时文件,然后将该文件传递给PdfReader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM