How to specify a physical path on disc to a file, but acces a memory location?
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 consis开发者_C百科ting 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
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.
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
If the RTF library supports loading RTF files from the internet using WebRequest
, you could call WebRequest.RegisterPrefix
to make it call your own WebRequest
class for specific Uri
s. If it only uses WebRequest
for paths that begin with http
, you could register the prefix http://MyNonExistantDomain.internal/
.
精彩评论