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()