473,667 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

All files corrupted using Response.Write or Response.Binary Write in .NET 1.1

I have a very simple code snippet here:

private void Page_Load(objec t sender, System.EventArg s e)
{
string filePath =
Server.MapPath( "\\Transcriber\ \TranscriberTes t\\");
string fileName = "Test.Zip";
//FileInfo fi = new FileInfo(filePa th + fileName);
FileStream fs = File.Open(fileP ath + fileName,FileMo de.Open);

byte[] fileData = new byte[fs.Length];
fs.Write(fileDa ta,0,(int)fs.Le ngth);
fs.Close();

HttpContext.Cur rent.Response.C lear();
HttpContext.Cur rent.Response.C learHeaders();
HttpContext.Cur rent.Response.C learContent();

HttpContext.Cur rent.Response.C ontentType = "applicatio n/zip";
HttpContext.Cur rent.Response.A ddHeader("Conte nt-disposition",
"attachment ; filename=" + fileName);
HttpContext.Cur rent.Response.B inaryWrite(file Data);
//HttpContext.Cur rent.Response.W riteFile(filePa th +
fileName,0,(int )fi.Length);
HttpContext.Cur rent.Response.E nd();

}

<end snippet>

No matter what I tweak, the Zip file (I have tried .MP3, PDF to no
avail as well) is corrupt.
I have tried application/octet-stream and application/x-unkown for the
ContentType.

BinaryWrite, and A straight writefile produce the same results - a
corrupt file.

Anyone feeling charitable out there?

Thanks,
Chris

Oct 4 '06 #1
1 9345
Try commenting out Response.ClearH eaders()
Ch************* **@gmail.com wrote:
I have a very simple code snippet here:

private void Page_Load(objec t sender, System.EventArg s e)
{
string filePath =
Server.MapPath( "\\Transcriber\ \TranscriberTes t\\");
string fileName = "Test.Zip";
//FileInfo fi = new FileInfo(filePa th + fileName);
FileStream fs = File.Open(fileP ath + fileName,FileMo de.Open);

byte[] fileData = new byte[fs.Length];
fs.Write(fileDa ta,0,(int)fs.Le ngth);
fs.Close();

HttpContext.Cur rent.Response.C lear();
HttpContext.Cur rent.Response.C learHeaders();
HttpContext.Cur rent.Response.C learContent();

HttpContext.Cur rent.Response.C ontentType = "applicatio n/zip";
HttpContext.Cur rent.Response.A ddHeader("Conte nt-disposition",
"attachment ; filename=" + fileName);
HttpContext.Cur rent.Response.B inaryWrite(file Data);
//HttpContext.Cur rent.Response.W riteFile(filePa th +
fileName,0,(int )fi.Length);
HttpContext.Cur rent.Response.E nd();

}

<end snippet>

No matter what I tweak, the Zip file (I have tried .MP3, PDF to no
avail as well) is corrupt.
I have tried application/octet-stream and application/x-unkown for the
ContentType.

BinaryWrite, and A straight writefile produce the same results - a
corrupt file.

Anyone feeling charitable out there?

Thanks,
Chris
Nov 23 '06 #2

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

Similar topics

3
16460
by: PorkyJr | last post by:
Running an asp page that has the following code: <% response.Write MonthName(Month(date)) %> &nbsp; <% response.Write Day(date) %> ,
1
4614
by: news | last post by:
I'm trying to encapsulate a bunch of html widgets such that a containing page can call them to draw themselves in whatever order it chooses as well as easily add new ones. In order to do this each widget registers itself by returning an id code and a reference to the subroutine that generates its HTML content. This works fine using vbScript's GetRef, but I've just noticed that if the subroutine you get a reference to contains any...
9
6336
by: msuk | last post by:
All, I have a well form block of XML that is stored in a C# string type and I just simply want to display it in the browser using Response.Write but when I try this I get the following error: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
11
26845
by: Russ | last post by:
My web app writes some binary data to a file at the client site via Response.Write and Response.BinaryWrite. This action is accomplished in response to a button click, with C# code behind as follows: private void SubmitButton_Click (object sender, System.EventArgs e) { // Set up the response to write the print file to the client Response.Clear (); Response.AppendHeader ("Content-Disposition", "filename=WebPrint.prn");
6
6118
by: Abel Chan | last post by:
Hi there, I am trying to use ASP.NET to populate list of files with hyper link from a specific directory. The following code works well but it populates the list to the top of the web page. I have header and footer defined on the web page. How could I write the list to the body session like a specific area, a table or a list box control? Thanks in advance.
3
6428
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating imagebuttons which point to a dummy page that takes the image and displays it via response. All works fine if I use explicit paths to a file (response.writefile(<filename>) or directly pass through the database image...
6
7130
by: Luke Davis | last post by:
I can't figure this out, why am I getting ")" expected and ";" expected on this line? Response.Write("<input type=""hidden"" name=""item_number"" value="".COM, MLSNumber"">"); - L
7
3296
by: Jim in Arizona | last post by:
I'm brand new at ajax. In fact, about 20 minutes ago was the first time I got it to work. The problem I'm having on another page did not work, however. I'm running into the following error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server...
4
4431
by: Abubakar | last post by:
Hi, I'm working on an application whose code was written by some other developer and I dont completely understand its source code right now. In one of the pages where I'm writing a test code, at the end of the Page_Load event I write a simple following line: if (IsPostBack) { Response.Write("say"); }
0
8363
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8787
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6203
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
5672
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
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.