473,769 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best practice for streaming fairly large files from server to clie

Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream (maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
--
Regards,

Phil Johnson (MCAD)
Nov 27 '07 #1
7 2860
One possible option is to redirect the browser to the file location itself.
If the file is stored in a non-http accessible folder, you could copy it
into a temp folder for download. Of course, then you have to clean it up at
some point and there is a potential security risk as other users could also
download the file.

Barring that, I think what you said would be fine. Just read chunks from a
FileStream and buffer them to the Response.

Scott
"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:CD******** *************** ***********@mic rosoft.com...
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole
file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream
(maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
--
Regards,

Phil Johnson (MCAD)
Nov 27 '07 #2
http://groups.google.com/group/micro...13224a77b89add
See if the WriteTextFile in the HttpHelper will help you.
If it does, please post back here.

I ~think that is what you're looking for.

"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:CD******** *************** ***********@mic rosoft.com...
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole
file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream
(maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
--
Regards,

Phil Johnson (MCAD)

Nov 27 '07 #3
Thanks for your thoughts Scott...

It looks like buffering the filestream in chunks is going to be the best
option... the files will be temporary files and I need to delete them as soon
as the data has been streamed.

--
Regards,

Phil Johnson (MCAD)
"Scott Roberts" wrote:
One possible option is to redirect the browser to the file location itself.
If the file is stored in a non-http accessible folder, you could copy it
into a temp folder for download. Of course, then you have to clean it up at
some point and there is a potential security risk as other users could also
download the file.

Barring that, I think what you said would be fine. Just read chunks from a
FileStream and buffer them to the Response.

Scott
"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:CD******** *************** ***********@mic rosoft.com...
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole
file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream
(maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
--
Regards,

Phil Johnson (MCAD)

Nov 27 '07 #4
first turn of buffering for the page. then use Response.Write in chunks,
or if its an actual file, the builtin Reponse.WriteFi le
(which just read and writes chunks via .Write).
-- bruce (sqlwork.com)

Phil Johnson wrote:
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream (maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
Nov 27 '07 #5

I use a "double guid" solution here sometimes.

C:\stuff\

http://www.mycompany.com/stuff/
string folderName = System.Guid.New Guid().ToString ("N");
string fileName = System.Guid.New Guid().ToString ("N");
Which gives me something like this (if I'm writing out a txt file)
C:\stuff\\D680E B2590A542F7828A 7F33CF705563\2D B610825821412F8 C5CCFA3C642FEE2 .txt
or
http://www.mycompany.com/stuff/D680E...A3C642FEE2.txt

Aka, a po' man's security model.
Its ugly, but if somebody guesses 2 guid's..... they totally rock.

...

That is if the information is sensitive.

Naturally, I have to clean up:
C:\stuff\

periodically.


"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:A4******** *************** ***********@mic rosoft.com...
Thanks for your thoughts Scott...

It looks like buffering the filestream in chunks is going to be the best
option... the files will be temporary files and I need to delete them as
soon
as the data has been streamed.

--
Regards,

Phil Johnson (MCAD)
"Scott Roberts" wrote:
>One possible option is to redirect the browser to the file location
itself.
If the file is stored in a non-http accessible folder, you could copy it
into a temp folder for download. Of course, then you have to clean it up
at
some point and there is a potential security risk as other users could
also
download the file.

Barring that, I think what you said would be fine. Just read chunks from
a
FileStream and buffer them to the Response.

Scott
"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:CD******* *************** ************@mi crosoft.com...
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream
uses
its WriteTo method to write to the responses output stream. With
larger
files (250 mb) I get a system out of memory exception because the whole
file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream
(maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
--
Regards,

Phil Johnson (MCAD)


Nov 27 '07 #6
Thanks for all the responses, they certianly got me pointed in the right
direction.... after doing a bit of looking online for the response.write in
chunks method I found this great example from Microsoft.... only requires
changing the string for the filename/path.....

http://support.microsoft.com/?kbid=812406

--
Regards,

Phil Johnson (MCAD)
"bruce barker" wrote:
first turn of buffering for the page. then use Response.Write in chunks,
or if its an actual file, the builtin Reponse.WriteFi le
(which just read and writes chunks via .Write).
-- bruce (sqlwork.com)

Phil Johnson wrote:
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream uses
its WriteTo method to write to the responses output stream. With larger
files (250 mb) I get a system out of memory exception because the whole file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream (maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.
Nov 28 '07 #7
Thanks for the followup post... about a concrete solution.

"Phil Johnson" <Ph*********@di scussions.micro soft.comwrote in message
news:6A******** *************** ***********@mic rosoft.com...
Thanks for all the responses, they certianly got me pointed in the right
direction.... after doing a bit of looking online for the response.write
in
chunks method I found this great example from Microsoft.... only requires
changing the string for the filename/path.....

http://support.microsoft.com/?kbid=812406

--
Regards,

Phil Johnson (MCAD)
"bruce barker" wrote:
>first turn of buffering for the page. then use Response.Write in chunks,
or if its an actual file, the builtin Reponse.WriteFi le
(which just read and writes chunks via .Write).
-- bruce (sqlwork.com)

Phil Johnson wrote:
Hello,

I have an issue with some code I am updating:

An entire file is loaded into a memory stream then that memory stream
uses
its WriteTo method to write to the responses output stream. With
larger
files (250 mb) I get a system out of memory exception because the whole
file
is loaded into RAM.

I need to modify this so the file is buffered into the output stream
(maybe
via a filestream?) to avoid the whole file being loaded into ram.

Does anybody have any good example code or links of how to do this?

Thanks in advance for any help.

Nov 28 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9269
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
1
1450
by: Andy Fish | last post by:
Hi, I am about to commence the design of what will turn out to be a fairly large asp.net web app, and I am looking for any good advice and resources (books, web pages) concerning how best to structure it. I would consider myself an experienced software designer and technical architect - I certainly know enough to know that I don't know everything, and I'm keen to pick up on current best practice. I have architected large server apps...
3
2341
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file must be the only method that users receive image files.
5
2532
by: BK | last post by:
We've got a fairly large scale development process under way in .NET 2003. We are about a month away from go-live for phase 1, second phase is rather short and all work should be completed in the next 2 months. Looking back on problems encountered, we want to learn from this project. FWIW, we are nearly on time with the original time line (only off by about a month), and we actually added more functionality than the original specs...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9981
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9850
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8862
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.