Web Forms :: OutOfMemoryException Using FileStream With FAT BIG FILE For Send To Response?
May 11, 2010
I'm using Filestream for read big file (> 500 MB) and I get the OutOfMemoryException. Any solutions about it??
I want this in my app:
Read DATA from Oracle
Uncompress file using FileStream and BZip2
Read file uncompressed and send it to asp.net page for download. When I read file from disk, Fails !!! and get OutOfMemory.
. My Code is:
using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
{
byte[] b2 = ReadFully(fs3, 1024);
}
// http://www.yoda.arachsys.com/csharp/readbinary.html
public static byte[] ReadFully(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
{
read += chunk;
// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
// End of stream? If so, we're done
if (nextByte == -1)
{
return buffer;
}
// Nope. Resize the buffer, put in the byte we've just
// read, and continue
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
}
}
// Buffer is now too big. Shrink it.
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}
View 1 Replies
Similar Messages:
Jan 25, 2010
I've got a vb.net page that when a user clicks a button in a gridview, it copys the file (row seleted) in the gridview as "Label2" from the webserver to the users pc. (We had to setup a lot of security to get it so the webserver could copy to the users pc). I have that all working fine, but now, I'm trying to see if FileStream will then open the file that was just downloaded on the users PC. I'm not familiar with FileStream, and could use a little push in the right direction. (Disclaimer, yes I know downloading the file directly to the pc is a crazy thing to do, but it's a really long story. :-)
For the FileStream portion, I found this sample, but don't quite understand if I can incorporate it into my button click event. Here's the sample [URL]
[Code]....
[Code]....
[Code]....
View 3 Replies
May 20, 2010
I'm using Filestream for read big file (> 500 MB) and I get the OutOfMemoryException. Any solutions about it?? I want this in my app asp.net: Read DATA from Oracle Uncompress file using FileStream and BZip2 Read file uncompressed and send it to asp.net page for download. When I read file from disk, Fails !!! and get OutOfMemory. My Code is:
using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
{
byte[] b2 = ReadFully(fs3, 1024);
}
// [URL]
public static byte[] ReadFully(Stream stream, int initialLength)
{
// If we've been passed an unhelpful initial length, just
// use 32K.
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
{
read += chunk;
// If we've reached the end of our buffer, check to see if there's
// any more information
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
// End of stream? If so, we're done
if (nextByte == -1)............................
View 8 Replies
Aug 25, 2010
There are bunch of files stored in a DataBase as varbinary/image data. I am writing a program to extract these file data and send them to the browser so file can be opened or saved. My method is,
[code]....
BUT this method creates a file in the Server and then transmit to the browser. Means 100s of files will be created in the server when I open 100s of files with this process, naturally I want to avoid that.
Is it possible to do this without creating a copy of the file in the server ?
View 3 Replies
Feb 22, 2010
i have a file upload control in my page and have set the max file size in web.config to 1 GB (this is an intranet app).
However, when I try to upload a 280 MB file, it throws System.OutOfMemoryException. The server has 4 GB of RAM and plenty of disk space.
View 4 Replies
Jun 21, 2010
I have a class DocumentGenerator which wraps a MemoryStream. So I have implemented IDisposable on the class.
I can't see how/where I can possibly dispose it though.
This is my current code, which performs a file download in MVC:
using (DocumentGenerator dg = DocumentGenerator.OpenTemplate(path))
{
/* some document manipulation with the
DocumentGenerator goes here ...*/
return File(dg.GetDocumentStream(), "text/plain", filename);
}
This errors as the stream is closed/disposed before the controller has finished with it. How can I make sure my resources are properly disposed in this situation?
EDIT: My implementation of IDisposable at the moment just disposes the MemoryStream. I know it's not a proper implementation, I just used it as a test. Is there something different I could do here to make it work?
public void Dispose()
{
_ms.Dispose();
_ms = null;
}
View 2 Replies
Dec 23, 2010
Can we get the doc type and contenttype of a file from the filestream field?
View 2 Replies
Jan 12, 2010
I am trying to send email on button click and i did it sucessfully...
but now i am try to autorespond of same mail.. here i will define my problem..
my aspx page code:-
[code]
View 5 Replies
Nov 22, 2015
How to send request from one domain to another. And also get the response from that domain?
View 1 Replies
Jun 7, 2010
I'm rewriting a messaging module and the old asp application has a send button image and it used HTML submit button. My new application is asp.net. Can I use the asp send button image to response.redirect to the View message page?
View 3 Replies
Jun 1, 2010
I am getting my Request from a third party application(different domain) to my ASP application. I am handling the request and doing the business part in my application and as a acknowledgement I need to send XML string as Response to the same Page which POSTED the request to my Application. I was successful in retrieving the input from Request using the following code
NameValueCollection postPageCollection = Request.Form;
foreach (string name in postPageCollection.AllKeys)
{
... = postPageCollection[name]);
}
But i am not sure how to send back the response along with XML String to the site(different domain)?
EDIT: How to get the URL from where the POST happened.
View 2 Replies
Jul 23, 2010
I create my own litte ViewEngine, done many things that works great, but now I want something to implement, but I don't know how.
I want the final Response Content when the controller is executed and the view is executed, manuelly manipulate and than send to the client.
I have two Examples for it.
First I have an AssetManager, he collects all Css files and JavaScript files, given by components, the view, classes and so on.
And this collected links I will insert with String.indexOf before the "</head" tag.
The reason why I want do this in the engine and not with a line like this in the head part
[Code]....
Is that I want so save me the work to do this every time on each project in the master page and maybe in single views.
A second usefull idea is, I want to write my own litte trace component, and I want so write the generated content before the "</html>" tag.
where I can manipulate the content before sending it to the client, and this in the engine?
View 3 Replies
Aug 23, 2010
I am trying to create a web service that can do the following functionality:
Request XML
[Code]....
How can I create web service to do this.
View 1 Replies
Jun 17, 2010
I have a webservice that sends the response back in XML format.I'm able to connect and call the webservice adding an external web reference to the Visual Studio project.Then in my code behind:As New servicename_addedLabel1.Text = servicename_added.Functionexposed(param1, param2, etc)With that code I can get the response in a large label and unstructured data. If I "view source" I see the XML structured data.I have tried to create an XML document without success.My goal is to parse the response and write it to a database separating all the fields.
View 5 Replies
Jan 19, 2010
I need to serve MP3 content that is generated dynamically during the request. My clients (podcatchers I can't configure) are timing out before I'm able to generate the first byte of the response data.
Is there a way to send fodder/throwAway data while I'm generating the real data, to prevent/avoid the timeout, but in a way that allows me to instruct the client to ignore/discard the fodder data once I'm ready to start sending the "real" data?
View 2 Replies
Apr 27, 2016
I have an asp.net panel having various controls including gridview. I have converted this panel into pdf and attached it as an email attachment using memory stream. Everything is working fine. Now I have an File upload control outside panel through which I have to attach a file and send it in mail along with the already attached panel. But I am unable to figure out how to do it.
View 1 Replies
Jul 13, 2010
I'm trying to implement the SQL Filestream feature so that I can store the physical PDF on hard disk, while still allowing full-text searching. I've set up my database to allow filestreaming, and as far as I know, have made the table correctly (I set it up based on this article: http://msdn.microsoft.com/en-us/library/cc949109(SQL.100).aspx). I'm just a bit confused about how it's supposed to work, and what steps I need to manually perform.
My understanding is that I convert the PDF to binary and store the binary data in the varbinary(max) field designated as the "Filestream" field, and once the data is stored, the physical PDF file will automatically be placed in the directory I specified when I set up the Filestream option in SQL server. I can also store the file name and extension for retrieval purposes, but the file must be streamed, rather than accessed directly. Is this all true?
What's currently happening is that I save the binary data to the table, but nothing else happens - a file never shows up on the server. The only contents of the directory are two empty folders named: $FSLOG, and, 9953ffec-7c59-41ce-943d-98073853ba0d, and a HDR file named "filestream". Do I need to manually save the file to disk, in addition to saving the binary data?
View 10 Replies
Mar 8, 2011
i need to response a file to a new window. here my code. pls guide me what i have to add.
[Code]....
View 4 Replies
Mar 31, 2010
I have following function which is called from a button click event
[Code]....
I am creating a zip file on the fly and wanted to download this file.Problem is that in Internet explorer when I click the button the download accelrator comes with file name as my page saying resume opendialogueif i click open then DAP window close and normal windows download manager comes but the event of my button fires multiple time?I don't know what to do with it
View 6 Replies
May 14, 2010
I'm using a web form that allows users to upload media files. The code works great on small to medium size files, but I've found that if a file is really big(like bigger than 15MB), the user will get a 404 error. Currently I'm using the code below to handle the file. Does .NET provide another way to handle larger files?
[Code]....
View 6 Replies
Feb 8, 2010
I have one issue , on that page i have Gridview ie: binding data(by making relationship b/w two tables ) ie: each row contains 75 EasyListbox control so it will be visible as per the condition ie: getting from Database.
But when the page_Loads on that page - First rows shows correctly ie: when i click on paging for Second page - it shows error like this
[code]....
View 13 Replies
Jan 6, 2011
Below I have some code that I am using to give the user the option to save or open a file. However, for whatever reason, when it does this it appends everything that is in my .aspx page to the end of my file. I've no clue why this is happening or how to fix.
[Code]....
View 3 Replies
Feb 4, 2010
How do I write Response.OutputStream to a file preferably in C#?
View 2 Replies
Jan 8, 2010
I am using a gridview to display (open or save) files that have been uploaded into a SQL 2005 server. I have a templatefield within the gridview that contains a linkbutton that does a postback to GetUploadedFile.aspx that then fires the response.binarywrite() code. The code seems to work fine and opens/saves the files correctly. But once this has completed and I try and click on another button on the page, instead of doing the appropriate action it re-fires the getuploadedfile.aspx binarywrite code and opens up the "Open/Save/Cancel" dialog again.
[Code]....
[Code]....
[Code]....
View 4 Replies
Oct 18, 2010
I have an issue with trying to create a Pdf file from my webpage. Basically, everythig involving creating the Pdf (using iTextSharp) is done, and I'm doing this as a File Stream (i.e, I'm saving the Pdf on local machine). Now what I'm trying to do is create it as a Memory Stream (i.e, open the Pdf from the browser). I was able to do this earlier when I wa still at the 1st version of the application, and all of the code behind was incluced in my .aspx.cs file. But now, I've kept the code in the .aspx.cs at a minimum and put the cude in classes and I'm creating onjects of thoses classes from the .aspx.cs
The problem is that the code from creating the Memory Stream is in a class as follows:
[Code]....
As you can imagine, the compiler cannot recognise "Response" as it's in a seperate class instead of in .aspx.cs
View 5 Replies