Is there anyway to stream an automated file without saving to disk

Is there anyway to stream an automated file without saving to disk

am 30.11.2007 16:42:00 von Karl

Hi all,

It may seem like a rather odd request (or not) but I would like to be
able to create a file (doc, jpg, xls or one of many other files that
can be automated) on a website and stream it to a user without saving
it to the disk first.

Obviously saving the file first and streaming it afterwards is fairly
easy to do, but it relies on disk write permissions on the server and
you'd have to make sure the file was removed afterwards.

I'd like to be able to dynamically create a file and stream this to
the user. Can anyone tell me if this is possible? If so, samples,
examples and weblinks to such would be appreciated...

Re: Is there anyway to stream an automated file without saving to disk first?

am 30.11.2007 18:36:56 von Morten Wennevik

Hi Karl,

You can use a MemoryStream to hold the data, and have the MemoryStream feed the webresponse


On Fri, 30 Nov 2007 16:42:00 +0100, Karl wrote:

> Hi all,
>
> It may seem like a rather odd request (or not) but I would like to be
> able to create a file (doc, jpg, xls or one of many other files that
> can be automated) on a website and stream it to a user without saving
> it to the disk first.
>
> Obviously saving the file first and streaming it afterwards is fairly
> easy to do, but it relies on disk write permissions on the server and
> you'd have to make sure the file was removed afterwards.
>
> I'd like to be able to dynamically create a file and stream this to
> the user. Can anyone tell me if this is possible? If so, samples,
> examples and weblinks to such would be appreciated...
>
>



--
Happy coding!
Morten Wennevik [C# MVP]

Re: Is there anyway to stream an automated file without saving todisk first?

am 30.11.2007 20:12:05 von Harlan Messinger

Karl wrote:
> Hi all,
>
> It may seem like a rather odd request (or not) but I would like to be
> able to create a file (doc, jpg, xls or one of many other files that
> can be automated) on a website and stream it to a user without saving
> it to the disk first.
>
> Obviously saving the file first and streaming it afterwards is fairly
> easy to do, but it relies on disk write permissions on the server and
> you'd have to make sure the file was removed afterwards.
>
> I'd like to be able to dynamically create a file and stream this to
> the user. Can anyone tell me if this is possible? If so, samples,
> examples and weblinks to such would be appreciated...
>
Why do you need an intermediary stage at all? Why not just write
directly to Response?

Re: Is there anyway to stream an automated file without saving to

am 03.12.2007 10:45:43 von Karl

On 30 Nov, 17:36, "Morten Wennevik [C# MVP]"
wrote:
> Hi Karl,
>
> You can use a MemoryStream to hold the data, and have the MemoryStream feed the webresponse
>
>
>
> On Fri, 30 Nov 2007 16:42:00 +0100, Karl wrote:
> > Hi all,
>
> > It may seem like a rather odd request (or not) but I would like to be
> > able to create a file (doc, jpg, xls or one of many other files that
> > can be automated) on a website and stream it to a user without saving
> > it to the disk first.
>
> > Obviously saving the file first and streaming it afterwards is fairly
> > easy to do, but it relies on disk write permissions on the server and
> > you'd have to make sure the file was removed afterwards.
>
> > I'd like to be able to dynamically create a file and stream this to
> > the user. Can anyone tell me if this is possible? If so, samples,
> > examples and weblinks to such would be appreciated...
>
> --
> Happy coding!
> Morten Wennevik [C# MVP]

This sounds like a great way to do exactly what I want, but I've had a
couple of attempts at creating an Excel spreadsheet by automation and
saving it to the MemoryStream, but with no success. I've attached some
simple code here to show what I'm trying to do. Perhaps someone could
tweak it so that it ends up with a successfull stream which I can
output to a browser?


Dim memStream As New MemoryStream(1000000)

Dim Excel As New Application
Dim WB As Workbook = Excel.Workbooks.Add()
Dim WS As Worksheet = WB.Worksheets("Sheet1")
Dim numX As Integer = 1

WS.Range("a" & numX).Value = "ColumnA"
WS.Range("b" & numX).Value = "ColumnB"
WS.Range("c" & numX).Value = "ColumnC"
WS.Range("d" & numX).Value = "ColumnD"
WS.Range("e" & numX).Value = "ColumnE"
WS.Range("a" & numX).Font.Bold = True
WS.Range("b" & numX).Font.Bold = True
WS.Range("c" & numX).Font.Bold = True
WS.Range("d" & numX).Font.Bold = True
WS.Range("e" & numX).Font.Bold = True
For numX = 2 To 10
WS.Range("a" & numX).Value = "A" & numX.ToString()
WS.Range("b" & numX).Value = "B" & numX.ToString()
WS.Range("c" & numX).Value = "C" & numX.ToString()
WS.Range("d" & numX).Value = "D" & numX.ToString()
WS.Range("e" & numX).Value = "E" & numX.ToString()
Next

WB.SaveAs(memStream, XlFileFormat.xlWorkbookNormal)
WB.Close()
Excel.Workbooks.Close()
Excel.Quit()
Excel = Nothing
GC.Collect()

Re: Is there anyway to stream an automated file without saving to

am 03.12.2007 10:48:00 von Karl

On 30 Nov, 19:12, Harlan Messinger
wrote:
> Karl wrote:
> > Hi all,
>
> > It may seem like a rather odd request (or not) but I would like to be
> > able to create a file (doc, jpg, xls or one of many other files that
> > can be automated) on a website and stream it to a user without saving
> > it to the disk first.
>
> > Obviously saving the file first and streaming it afterwards is fairly
> > easy to do, but it relies on disk write permissions on the server and
> > you'd have to make sure the file was removed afterwards.
>
> > I'd like to be able to dynamically create a file and stream this to
> > the user. Can anyone tell me if this is possible? If so, samples,
> > examples and weblinks to such would be appreciated...
>
> Why do you need an intermediary stage at all? Why not just write
> directly to Response?

Simply because I don't know how Id write a file directly to the
response object. I know how to create individual objects (jpg , Excel
etc) but I only know how to save these to the file system afterwards.
This is what I'm trying to avoid and to send the file out to a users
browser directly without saving to disk.

Re: Is there anyway to stream an automated file without saving to

am 27.12.2007 14:48:27 von Karl

On 3 Dec, 09:48, Karl wrote:
> On 30 Nov, 19:12, Harlan Messinger
> wrote:
>
>
>
> > Karl wrote:
> > > Hi all,
>
> > > It may seem like a rather odd request (or not) but I would like to be
> > > able to create a file (doc, jpg, xls or one of many other files that
> > > can be automated) on a website and stream it to a user without saving
> > > it to the disk first.
>
> > > Obviously saving the file first and streaming it afterwards is fairly
> > > easy to do, but it relies on disk write permissions on the server and
> > > you'd have to make sure the file was removed afterwards.
>
> > > I'd like to be able to dynamically create a file and stream this to
> > > the user. Can anyone tell me if this is possible? If so, samples,
> > > examples and weblinks to such would be appreciated...
>
> > Why do you need an intermediary stage at all? Why not just write
> > directly to Response?
>
> Simply because I don't know how Id write a file directly to the
> response object. I know how to create individual objects (jpg , Excel
> etc) but I only know how to save these to the file system afterwards.
> This is what I'm trying to avoid and to send the file out to a users
> browser directly without saving to disk.

bump...