By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Is there anyway to stream an automated file without saving to diskfirst?

P: n/a
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...

Nov 30 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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 <go**********@cortexa.co.ukwrote:
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]
Nov 30 '07 #2

P: n/a
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?
Nov 30 '07 #3

P: n/a
On 30 Nov, 17:36, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.comwrote:
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 <googlegro...@cortexa.co.ukwrote:
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()
Dec 3 '07 #4

P: n/a
On 30 Nov, 19:12, Harlan Messinger <hmessinger.removet...@comcast.net>
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.
Dec 3 '07 #5

P: n/a
On 3 Dec, 09:45, Karl <googlegro...@cortexa.co.ukwrote:
On 30 Nov, 17:36, "Morten Wennevik [C# MVP]"

<MortenWenne...@hotmail.comwrote:
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 <googlegro...@cortexa.co.ukwrote:
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()
Bump...
Dec 10 '07 #6

P: n/a
On 3 Dec, 09:48, Karl <googlegro...@cortexa.co.ukwrote:
On 30 Nov, 19:12, Harlan Messinger <hmessinger.removet...@comcast.net>
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...
Dec 27 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.