如何指定磁盘上文件的物理路径,但访问内存位置?
我正在尝试集成多个组件来构建自定义报告解决方案。这些组件之一是基于模板的报告生成器。它读取由带有占位符的 RTF 文件组成的模板并执行替换。这非常有效,并生成 RTF 报告。
尽管它可以将结果生成为流而不是物理 RTF 文件,但它有一个属性用于指定模板(输入)文件的全名。这在桌面应用程序上是可以的,但在谈论 WCF 服务时,我想避免在硬盘中需要有物理文件。
所有模板都存储在数据库中。应用程序从那里将其作为流读取,然后将其作为 RTF 文件保存到 HD。 我想知道在 C# 中是否有可能以这样的方式“欺骗”报告生成器:我可以指定一个由某种“虚拟”或“虚构”路径组成的字符串,然后组件将打开来自内存流的模板,因为它是光盘上的真实物理路径。
任何帮助将不胜感激。
提前致谢,
贡萨洛
I'm trying to integrate several components to build a custom reporting solution. One of these components is a template-based report generator. It reads a template consisting on a RTF file with placeholders and perform the substitution. This works great, and generates an RTF report.
Although it can generate the results as a stream instead of a physical RTF file, it has a property meant to specify the full name for the template (input) file. This is Ok on desktop applications but when talking about a WCF Service I would like to avoid the need to have a physical file in the HD.
All the templates are stored inside a database. The application reads it from there as a stream and then saves it to the HD as an RTF file.
I'd like to know if it would be possible in c# to 'cheat' the report generator in such a way that I could specify a string consisting on a kind of 'virtual' or 'fictitious' path and then the componet would open the template from a memory stream as it was a real physical path on disc.
Any help will be appreciated.
Thanks in advance,
Gonzalo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据报告解决方案的工作方式,您也许可以使用命名管道。有关详细信息,请参阅此 MSDN 页面,但基本要点是您将调用
CreateNamedPipe
并指定您要使用的名称(采用该 MSDN 页面上列出的格式),然后将该名称作为文件名传递到您的报告解决方案。Depending on how the reporting solution works, you may be able to use a named pipe. See this MSDN page for more information, but the basic gist is that you would call
CreateNamedPipe
and specify the name you want to use (in the format listed on that MSDN page), then pass that name as the file name to your reporting solution.在 C# 4 中,您可以使用内存映射文件: http://weblogs.asp.net/gunnarpeipman/archive/2009/06/21/net-framework-4-0-using-memory-mapped-files.aspx
In C# 4 you can use memory mapped files: http://weblogs.asp.net/gunnarpeipman/archive/2009/06/21/net-framework-4-0-using-memory-mapped-files.aspx
如果 RTF 库支持使用
WebRequest
从 Internet 加载 RTF 文件,您可以调用WebRequest.RegisterPrefix
使其针对特定Uri
WebRequest 类>s。如果它仅对以http
开头的路径使用WebRequest
,您可以注册前缀http://MyNonExistantDomain.internal/
。If the RTF library supports loading RTF files from the internet using
WebRequest
, you could callWebRequest.RegisterPrefix
to make it call your ownWebRequest
class for specificUri
s. If it only usesWebRequest
for paths that begin withhttp
, you could register the prefixhttp://MyNonExistantDomain.internal/
.