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.EventArg s) Handles MyBase.Load
Dim path As String
Dim fs As New FileStream(path , FileMode.Open)
Dim byteRead As Integer
path = Server.MapPath( Request("fileTo Download"))
Response.ClearH eaders()
Response.Clear( )
Response.AddHea der("Content-Disposition", "attachment ; filename=" &
Request("fileTo Download").ToSt ring
Response.Conten tType = "applicatio n/XYZ"
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write( byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub 4 1558
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.AddHea der("Content-Disposition", "attachment ; filename=" &
Ali,
You are missing the ContentType setting.
Response.Conten tType = "applicatio n/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******** ******@TK2MSFTN GP11.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.AddHea der("Content-Disposition", "attachment ; filename=" &
Ali, You are missing the ContentType setting. Response.Conten tType = "applicatio n/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.Writef ile method.
Something like this should work:
Response.Clear( );
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-Disposition","a ttachment;filen ame=myfile.xls" );
Response.WriteF ile("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********@hot mail.com> wrote in message
news:Oq******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.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.AddHea der("Content-Disposition", "attachment ; filename=" &
Ali, You are missing the ContentType setting. Response.Conten tType = "applicatio n/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.ne t> wrote in message
news:#7******** ******@TK2MSFTN GP12.phx.gbl... To go along with Carl's answer, you can use the Response.Writef ile method. Something like this should work:
Response.Clear( ); Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der("Content-Disposition","a ttachment;filen ame=myfile.xls" ); Response.WriteF ile("myfile.xls ");
Here's more info: http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwebh ttpresponseclas swritefiletopic .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********@hot mail.com> wrote in message news:Oq******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.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.AddHea der("Content-Disposition", "attachment ; filename=" & >
Ali, You are missing the ContentType setting. Response.Conten tType = "applicatio n/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 audio file initiates client-side
streaming/playing of the audio file. Is there a way with Javascript to make
a left-click trigger a download of the file instead?
BTW, I don't want to have convert the mp3 file to winzip to make this
happen,...
|
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 Base Article
"How to Use the WebBrowser Control to Open Office Documents with
Visual C# .NET" which can be found here:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;304662
The application does what it's supposed to (ie Loads embeded Excel
|
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 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...
|
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 and read from Access files in C# application without having
Access in this PC in this case we install MDAC , Is there any thing similar
to MDAC for Excel ? if yes where can I download it ? what is the name of the
file ?
|
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 tested
it with large files, it blew up. (crashed the server, well documented
problem)
I can download a file just fine if I just point to the download file and let
IIS generate the download dialog (but with no security, of course)
| |
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 invalid or unrecognized response" /
"The connection with the server was reset"
I'm using Response.BinaryWrite to send down the file content as attachment
(sample codes is attached below). I read some of the similar posts in the
newsgroup about the...
|
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 will open correctly, but
other like Word, Excel and Powerpoint are corrupt. Here is code fragment to
upload:
// Get file in byte array
int fileLen = this.TextBoxFileToUpload.PostedFile.ContentLength;
|
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 auxilliary files such as these
must be downloaded "manually" in my code. My text-based files download
fine but I've ran into a problem downloading an .EXE. When it
downloads the file size is the same but it has been altered somehow
because a) the...
|
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 do I need to do? Thanks in advance.
|
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 non-privileged account. In the C#
program I would like to access the Document Library (using my credentials)
and make the proper file(s) available. I would like to pull the files locally
where I can provide them access.
One thought I had was to have the...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |