I am trying to allow a web user to download a file that exists in a
protected directory.
If I use the following sub, the contents of the file are written to the web
page, instead of prompting the user to save the file.
What am I doing wrong?
-R
Sub doDownload()
Response.Conten tType = "application\ms word"
Dim filename As String = New String("c:\\Tem p\\myDownload\\ hi.doc")
Dim downloadFile As System.IO.FileS tream = New
System.IO.FileS tream(filename, IO.FileMode.Ope n)
Response.Write( downloadFile.Le ngth() & "#")
downloadFile.Cl ose()
Response.WriteF ile(filename)
Response.Flush( )
Response.End()
End Sub 2 1328
Nothing. It is the client that decides how to handle different content types. Usually though, if a client has MS Word installed it either opens up in the web page, or opens up in Word itself. You can set this in Windows Explorer, under Tools... Folder Options ->File Types tab; look for the .doc extension and select Advanced, the check boxes there are self explanatory.
If the user does not have MS Word installed, the file download dialog will come up. There is a header that can be sent to force this, but it escapes me at the moment!
hope this helps,
sivilian
"rooster575 " wrote: I am trying to allow a web user to download a file that exists in a protected directory.
If I use the following sub, the contents of the file are written to the web page, instead of prompting the user to save the file.
What am I doing wrong?
-R
Sub doDownload() Response.Conten tType = "application\ms word" Dim filename As String = New String("c:\\Tem p\\myDownload\\ hi.doc") Dim downloadFile As System.IO.FileS tream = New System.IO.FileS tream(filename, IO.FileMode.Ope n) Response.Write( downloadFile.Le ngth() & "#") downloadFile.Cl ose() Response.WriteF ile(filename) Response.Flush( ) Response.End() End Sub
Add a line of code like this:
Response.AddHea der("Content-Disposition","a ttachment;filen ame=hi.doc");
The "attachment " part asks the browser to open the file outside of the
browser.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"rooster575 " <ro********@hot mail.com> wrote in message
news:Ov******** *****@TK2MSFTNG P09.phx.gbl... I am trying to allow a web user to download a file that exists in a protected directory.
If I use the following sub, the contents of the file are written to the
web page, instead of prompting the user to save the file.
What am I doing wrong?
-R
Sub doDownload() Response.Conten tType = "application\ms word" Dim filename As String = New String("c:\\Tem p\\myDownload\\ hi.doc") Dim downloadFile As System.IO.FileS tream = New System.IO.FileS tream(filename, IO.FileMode.Ope n) Response.Write( downloadFile.Le ngth() & "#") downloadFile.Cl ose() Response.WriteF ile(filename) Response.Flush( ) Response.End() End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nimesh |
last post by:
Hi All,
I am new to ASP.NET. I need to download a file from server to the client
machine.
Any ideas on how to go about this ?
Thanks In Advance.
|
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 to start the download process:
Response.Clear()
Response.ContentType = "text/plain"
Response.AppendHeader("Content-Disposition", "attachment; filename="
& fileName)
Response.AppendHeader("Content-Description", "This is your Cost
Journal...
|
by: James Wong |
last post by:
Hi! everybody,
I'm facing a quite strange download problem. I use the following code to
download an XML file to client side:
With Response
' clear buffer
Call .Clear()
' specify the type of the downloadable file
|
by: John Smith Jr. |
last post by:
Is there a way to have the server send a file to client (ie download) from a
button click and a filename string?
|
by: MW de Jager |
last post by:
Hi
I want to make a download link on my ASP page, however if I use a Hyperlink,
this just tries to open the file in the browser and does nothing if the file
is of an unknown type. If I right click the file, I can download it as
usual.
What do I do to get a button or a hyperlink to open the file download dialog
when such a link clicked?
| |
by: Ken Varn |
last post by:
I have an ASP.NET page that incorporates the following code on a button
press.
private void DownloadTag_Command(object sender, CommandEventArgs e)
{
FileStream fs;
String Filename;
Filename = MapPath(e.CommandArgument as string); // Name of file
is passed in cmd arg.
|
by: tjfdownsouth |
last post by:
I have a site that allows a person to log in and get a list of files to
download for them. If the file size is under 65MB then everything is fine,
they click the download button and the save box pops up. But if the file is
larger than 65MB the page sits and processes until it times out. I can't
figure it out becaus a 64MB file loads immediately for download while one
slightly larger hangs up.
Any assistance on this will be greatly...
|
by: tshad |
last post by:
I have a function that downloads a file to the users computer and it works
fine.
The problem is that I then want the program to rename the file (file.move)
to the same name plus todays date.
The problem is that when you run the program it gets to the:
Response.AddHeader("Content-Disposition", "attachment; filename=" +
file.Name)
|
by: Khafancoder |
last post by:
Hi guys,
i am building a FileSharing website,
i wanna allow users to be able using download managers such as DAP to
download files from webserver but
don't allow them to retrive files url...
so i used Response.WriteFile but it won't trigger any download manager
such as DAP or FlashGet
i used this code :
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |