473,385 Members | 1,944 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,385 software developers and data experts.

Error while providing file download in webpage

Hello

I have to provide download of files in ASP.NET 2.0
I am using following lines of code.

try
{
Byte [] bytes = this.ContentController.GetFileContents(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=File" +
_fileExtension);
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Buffer = true;
Response.BinaryWrite(bytes);
Response.Flush();
}
catch(FileNotFoundException fnfe)
{
this.ShowErrorMessage(this.GetErrorString(Resource Identifiers.DOCUMENT_FILE_NOT_FOUND_ERROR));
}
catch(Exception ex)
{
this.ShowErrorMessage(this.GetErrorString(Resource Identifiers.DOCUMENT_UNEXPECTED_ERROR));
}
Using above code, when one clicks on file link, a default download box
of IE appears. If user clicks on Save, the file gets saved on disk and
user can open that file. If user clicks on Open, it opens registered
application with file type and says, file not found. Using same code I
am able to open Word file but I cannot open Excel, PDF files.

Note: My application used Master pages, UIP Application Blocks. The
code written above is inside a user control which gets loaded on view
(webform) dynamically based on configration(xml) file.

Please can anyone suggest what could be going wrong in the piece of
code because of which I am not able to open Excel/PDF files.

Apprciate your help.

Thanks and regards,
Ashsih Basran

Aug 3 '06 #1
2 1320
What do you mean you are "not able to open Excel/PDF files."

Is there an exception thrown, is the file saved incorrectly? Its
difficult to help out when we don't know the details.

Regards
Ray

as***********@hotmail.com wrote:
Hello

I have to provide download of files in ASP.NET 2.0
I am using following lines of code.

try
{
Byte [] bytes = this.ContentController.GetFileContents(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=File" +
_fileExtension);
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Buffer = true;
Response.BinaryWrite(bytes);
Response.Flush();
}
catch(FileNotFoundException fnfe)
{
this.ShowErrorMessage(this.GetErrorString(Resource Identifiers.DOCUMENT_FILE_NOT_FOUND_ERROR));
}
catch(Exception ex)
{
this.ShowErrorMessage(this.GetErrorString(Resource Identifiers.DOCUMENT_UNEXPECTED_ERROR));
}
Using above code, when one clicks on file link, a default download box
of IE appears. If user clicks on Save, the file gets saved on disk and
user can open that file. If user clicks on Open, it opens registered
application with file type and says, file not found. Using same code I
am able to open Word file but I cannot open Excel, PDF files.

Note: My application used Master pages, UIP Application Blocks. The
code written above is inside a user control which gets loaded on view
(webform) dynamically based on configration(xml) file.

Please can anyone suggest what could be going wrong in the piece of
code because of which I am not able to open Excel/PDF files.

Apprciate your help.

Thanks and regards,
Ashsih Basran
Aug 3 '06 #2

When I click in open, it starts Excel, and shows message saying -
c:\documents.....\Temporary Internet
files\Content.IE5\OBFADGE\Test[1].xls could not be found.

The same code workd if I download .doc file.
Ray Booysen wrote:
What do you mean you are "not able to open Excel/PDF files."

Is there an exception thrown, is the file saved incorrectly? Its
difficult to help out when we don't know the details.

Regards
Ray
Aug 3 '06 #3

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

Similar topics

2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
15
by: warlord | last post by:
I have a windows client app that is trying to download a file from a web server but I always get the following error when I call the GetResponse method of the Request object. The remote server...
0
by: VB Programmer | last post by:
I added a rich text editor to my webpage. When I run the form I get this error. Any ideas? Server Error in '/HtmlTest' Application....
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
23
by: wylbur37 | last post by:
I'm running an Apache server on my own computer (Windows XP Pro). I wrote a simple PHP script (called test3.php) that I'm running by putting the following URL in the address bar of the browser...
0
by: ravibrl | last post by:
Hey I need c++ code to access a webpage and download some software. If I execute that it should download that software and it should install it in my system. Give suggestions how to write that code...
2
by: NOSPAM plz | last post by:
Hey, My problem is, is it possible to download parts of a file while. i think is it is called threading My code thats download the whole webpage, and stunds the app while is is downloading: ...
2
by: =?Utf-8?B?Tmc=?= | last post by:
Hi. have someone can give me some idea how to start. the thing i want do is using web page export the sql data to text file then let user download. eg. the webpage has one button. when user...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.