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

Re: IO Problem by Jon

Jon
Mon Jun 27 14:42:01 CDT 2005

Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: IO Problem by Rahul

Rahul
Mon Jun 27 15:06:07 CDT 2005

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


"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1d2a66e8cc6974fd98c3c0@msnews.microsoft.com...
> Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> > 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.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: IO Problem by Jon

Jon
Mon Jun 27 15:21:40 CDT 2005

Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> 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?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: IO Problem by Rahul

Rahul
Mon Jun 27 15:34:15 CDT 2005

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

Thanks
Rahul

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1d2a702e4b1fa52998c3c7@msnews.microsoft.com...
> Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> > 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?
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: IO Problem by Jon

Jon
Tue Jun 28 01:04:50 CDT 2005

Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> 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 Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: IO Problem by Rahul

Rahul
Tue Jun 28 08:51:43 CDT 2005

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
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1d2af8e047e2a5d498c3ca@msnews.microsoft.com...
> Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> > 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 Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: IO Problem by Jon

Jon
Tue Jun 28 11:24:00 CDT 2005

Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: IO Problem by Rahul

Rahul
Wed Jun 29 10:02:39 CDT 2005

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.

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1d2b89ff31d075da98c3cb@msnews.microsoft.com...
> Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> > 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.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Re: IO Problem by Jon

Jon
Wed Jun 29 11:48:10 CDT 2005

Rahul <aggarwal.rahul@myfloridahouse.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too