IO Problem

  • Thread starter Thread starter Rahul
  • Start date Start date
R

Rahul

Problem Statement : I need to convert a pdf file on the file system into a
filestream and then pass this stream to the calling program. Once the steam
has been created I want to delete the file. The calling program then needs
to use that stream and open pdf file.

I know how to create the file stream. I cannot delete the file since there
is a filestream that is open for that file. Do I have to convert it into
some other stream like Memory Stream? If yes, then how?

Also how can the calling program use the stream to open the pdf file.

Thanks
Rahul
 
Rahul said:
Problem Statement : I need to convert a pdf file on the file system into a
filestream and then pass this stream to the calling program. Once the steam
has been created I want to delete the file. The calling program then needs
to use that stream and open pdf file.

I know how to create the file stream. I cannot delete the file since there
is a filestream that is open for that file. Do I have to convert it into
some other stream like Memory Stream? If yes, then how?

Also how can the calling program use the stream to open the pdf file.

Just to be clear, are there actually two *processes* involved in this,
or is it really a caller within the same process?

In either case, if you want to delete the file as soon as the client
has started reading the data, you will indeed need to read it into
something like a MemoryStream. The easiest thing would be to read the
whole thing in (see http://www.pobox.com/~skeet/csharp/readbinary.html
for some sample code which can easily be adapted) and then reset the
MemoryStream to the position 0.
 
Thanks Jon, that helps.

You have solved the first problem for me. I also need to open the pdf file
using the memory stream. How can I do that?

What is happening is that the calling program sends some xml text to the
called program which is then converted into some other xml format and sent
to the publishing tool, which then converts it into pdf file. The called
program poles to see if the pdf file has been created. Once available, it
creates a memory stream out of it and sends it to the calling program. The
calling programme now needs to use the memory stream and open it in acrobat,
for the user to see the same.

Thanks
Rahul
 
Rahul said:
Thanks Jon, that helps.

You have solved the first problem for me. I also need to open the pdf file
using the memory stream. How can I do that?

You don't open the PDF file using the memory stream - you open it using
a FileStream, and read from that in chunks, writing each chunk into a
MemoryStream. When you've finished, the MemoryStream will hold the data
from the file, and you just need to set the position back to 0.
What is happening is that the calling program sends some xml text to the
called program which is then converted into some other xml format and sent
to the publishing tool, which then converts it into pdf file. The called
program poles to see if the pdf file has been created. Once available, it
creates a memory stream out of it and sends it to the calling program. The
calling programme now needs to use the memory stream and open it in acrobat,
for the user to see the same.

How are the two programs communicating?
 
Both are c# dotnet code. Calling program is in one assambly(desktop
application) and the called program is in a different assembly.

Thanks
Rahul
 
Rahul said:
Both are c# dotnet code. Calling program is in one assambly(desktop
application) and the called program is in a different assembly.

But how are you getting them to communicate? How are they "talking" to
each other? How are you intending to get the data from one to the
other? If would be easy if they were actually in the same program, but
if they're two different programs, it's a bit harder (not actually
difficult, just harder).
 
Jon,

You can think of it as a method in one object calling a method in another
object. Both objects being in the same assembly.

Thanks
Rahul
 
Rahul said:
You can think of it as a method in one object calling a method in another
object. Both objects being in the same assembly.

And both in the same process? That makes things much easier then. Just
return the MemoryStream you've created, and you should be fine.
 
Yes I am returning the memory stream, but how do I use that stream to open
the pdf document directly... without first saving it as a file and then
opening that file.
 
Rahul said:
Yes I am returning the memory stream, but how do I use that stream to open
the pdf document directly... without first saving it as a file and then
opening that file.

In terms of Acrobat? I suspect there may not be a way of doing that.
 
Back
Top