I need a functionality where my clients download Excel files and after they
do, I do some processing. Downloading is easily achieved using a anchor or
hyperlink tag, but that does not give me the full functionality I am after.
So, I came up with a way to download the files using a stream but after I
download the file and try to open it in Excel I get garbage.
This is the code I use for the download function. Please help if you have
any ideas or suggestions. Thanks in advance.
Ali
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String
Dim fs As New FileStream(path, FileMode.Open)
Dim byteRead As Integer
path = Server.MapPath(Request("fileToDownload"))
Response.ClearHeaders()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Request("fileToDownload").ToString
Response.ContentType = "application/XYZ"
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write(byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub 4 1544
Ali wrote: I need a functionality where my clients download Excel files and after they do, I do some processing. Downloading is easily achieved using a anchor or hyperlink tag, but that does not give me the full functionality I am after. So, I came up with a way to download the files using a stream but after I download the file and try to open it in Excel I get garbage.
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Ali,
You are missing the ContentType setting.
Response.ContentType = "application/vnd.ms-excel" http://support.microsoft.com/default...Product=aspnet
Also, please don't cross-post to so many newsgroups.
--
Thanks,
Carl Prothman
Microsoft ASP.NET MVP
Thanks Carl and I am sorry for cross posting. I just did not know any
better.
Your response assumes that I need to create an excel file using ASP.NET.
The problem is that I already have the Excel file on the server. All I want
to do is download it. But not using the anchor nor the hyperlink tags.
Ali http://support.microsoft.com/default...&Product=aspne
t
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message
news:#9**************@TK2MSFTNGP11.phx.gbl... Ali wrote: I need a functionality where my clients download Excel files and after they do, I do some processing. Downloading is easily achieved using a anchor or hyperlink tag, but that does not give me the full functionality I am after. So, I came up with a way to download the files using a stream but after I download the file and try to open it in Excel I get garbage.
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Ali, You are missing the ContentType setting. Response.ContentType = "application/vnd.ms-excel" http://support.microsoft.com/default...&Product=aspne
t Also, please don't cross-post to so many newsgroups.
--
Thanks, Carl Prothman Microsoft ASP.NET MVP
To go along with Carl's answer, you can use the Response.Writefile method.
Something like this should work:
Response.Clear();
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","attachment;filename=myfile.xls");
Response.WriteFile("myfile.xls");
Here's more info: http://msdn.microsoft.com/library/de...efiletopic.asp http://www.aspnetpro.com/NewsletterA...200309so_l.asp
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"Ali" <el********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP09.phx.gbl... Thanks Carl and I am sorry for cross posting. I just did not know any better.
Your response assumes that I need to create an excel file using ASP.NET. The problem is that I already have the Excel file on the server. All I
want to do is download it. But not using the anchor nor the hyperlink tags.
Ali http://support.microsoft.com/default...&Product=aspne t
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message news:#9**************@TK2MSFTNGP11.phx.gbl... Ali wrote: I need a functionality where my clients download Excel files and after they do, I do some processing. Downloading is easily achieved using a anchor or hyperlink tag, but that does not give me the full functionality I am after. So, I came up with a way to download the files using a stream but after I download the file and try to open it in Excel I get garbage.
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Ali, You are missing the ContentType setting. Response.ContentType = "application/vnd.ms-excel" http://support.microsoft.com/default...&Product=aspne t Also, please don't cross-post to so many newsgroups.
--
Thanks, Carl Prothman Microsoft ASP.NET MVP
Exactly what I needed Steve. Thanks Dude.
Ali
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:#7**************@TK2MSFTNGP12.phx.gbl... To go along with Carl's answer, you can use the Response.Writefile method. Something like this should work:
Response.Clear(); Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition","attachment;filename=myfile.xls"); Response.WriteFile("myfile.xls");
Here's more info: http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwebhttpresponseclasswritefiletopic.asp
http://www.aspnetpro.com/NewsletterA..._l/asp200309so
_l.asp -- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net Hire top-notch developers at http://www.able-consulting.com "Ali" <el********@hotmail.com> wrote in message news:Oq**************@TK2MSFTNGP09.phx.gbl... Thanks Carl and I am sorry for cross posting. I just did not know any better.
Your response assumes that I need to create an excel file using ASP.NET. The problem is that I already have the Excel file on the server. All I want to do is download it. But not using the anchor nor the hyperlink tags.
Ali http://support.microsoft.com/default...&Product=aspne t
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message news:#9**************@TK2MSFTNGP11.phx.gbl... Ali wrote: > I need a functionality where my clients download Excel files and > after they do, I do some processing. Downloading is easily achieved > using a anchor or hyperlink tag, but that does not give me the full > functionality I am after. So, I came up with a way to download the > files using a stream but after I download the file and try to open
it > in Excel I get garbage. > > Response.AddHeader("Content-Disposition", "attachment; filename=" & >
Ali, You are missing the ContentType setting. Response.ContentType = "application/vnd.ms-excel" http://support.microsoft.com/default...&Product=aspne t Also, please don't cross-post to so many newsgroups.
--
Thanks, Carl Prothman Microsoft ASP.NET MVP
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Oschler |
last post by:
Hello,
I have a web site that has an audio file on it that I make available for
download. Right now I'm using the "right-click/save-as" approach. This is
because left-clicking the link to the...
|
by: Luis Ferrao |
last post by:
Hi,
My Windows Forms application uses the WebBrowser control to
open an Excel file since OLE objects are gone in .Net. The application
is actualy a clone of the one found in the MS Knowledge...
|
by: Ali |
last post by:
I need a functionality where my clients download Excel files and after they
do, I do some processing. Downloading is easily achieved using a anchor or
hyperlink tag, but that does not give me the...
|
by: [Yosi] |
last post by:
Can I make an Excel file without having Excel in my PC ?
I want to create Excel files from my C# application , then open those files
later in another PC who have Excel installed .
As we can open...
|
by: Earl Teigrob |
last post by:
My company sells software and wants to provide downloadable product. Some of
these downloads will be full CD's of over 550M
I had everything working fine using Response.filewrite() but when we...
|
by: Jocelyn Duhaylungsod |
last post by:
I have been getting the following server errors sporadically while
downloading excel, csv or xml file.
Internet Explorer cannot download <file name> from <IP address>
"The server returned an...
|
by: Charlie |
last post by:
Hi:
I'm uploading documents into a SQL Server Image field and using
Response.BinaryWrite() to download or view them in the browser. Some doc
types like Adobe Illustrator and Photoshop files...
|
by: STEVE.KING |
last post by:
Greetings:
I need to download an executable and some other binary files (a C++
DLL) from a virtual directory in my WinForms application. No-Touch
Deployment manages my .NET code fine but...
|
by: rh |
last post by:
Hi,
I am using a Hyperlink control that links to an Excel file. I would like
the "File Download" dialog box to appear instead of the Excel file
automatically opening within the browser.
What...
|
by: Peter S. |
last post by:
There are some files in a Sharepoint document library that I need to access
from a C# Webcontrol. The problem is that when the user runs the ASP.NET
webpage they will be coming in with a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
|
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...
| |