473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
6 3330
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Umesh | last post by:
Hi, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a...
8
by: TJ | last post by:
I need to be able to pass a pointer to a (managed code) Stream object to a COM method so it can serialize its data into the stream. I have a C# application that makes uses of Randolf Duke's...
1
by: David | last post by:
Hello. How can I load uploaded (from HtmlInputFile.PostedFile Property) file into Stream object without saving it to disk? Can anybody show me some simple? Thank you.
9
by: msnews.microsoft.com | last post by:
Hello I have a .pdf (from a SQL DB field) and I wish to display it in a ASP.NET page (with the Adobe toolbar, or at least a print button..) Thank you
0
by: Umesh | last post by:
Hi Gurus, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
3
by: dgk | last post by:
This code sends a PDF but ends the application. How can I send the stream but keep the session running? Thanks. Dim ms As New system.io.memorystream Dim document As New iTextSharp.text.Document...
1
by: Dica | last post by:
i need to allow users to save files to my site without the use of a web form. as i'm not able to retrieve any of the file properites via the form field, how do i go about saving the file from the...
5
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.