473,792 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Downloading files

I have some code to allow me to send text files to my user. I am not
allowing them to view my directory. I am just downloading a file they
previously requested, which works some of the time.

Dim fs As FileStream
Dim strContentType As String
Dim strPath = "C:\My External\File Path\"
Dim strFileName As String = "TomsTest.t xt"
fs = File.Open(strPa th & strFileName, FileMode.Open)
Dim bytBytes(fs.Len gth) As Byte
fs.Read(bytByte s, 0, fs.Length)
fs.Close()
Response.AddHea der("Content-disposition", _
"attachment ; filename=" & strFileName)
Response.Conten tType = "applicatio n/octet-stream"
Response.Binary Write(bytBytes)
Response.End()

If I run this on an XP and the user has Automatic downloads of files
disabled, the user will get a blank page with all the text displaying on it.

If it is enabled, I get the Save As prompt and allows the user to save the
file.

This can be confusing to the user. Is there a way for me to know if the
user will have a problem with the download?

This is not an automatic download, the user is actually pushing a button
saying he wants to download the file.

Thanks,

Tom
Mar 8 '06 #1
1 1746
Your bes bet would be to write a custom HttpHandler for delivering .txt
files.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uX******** ******@tk2msftn gp13.phx.gbl...
I have some code to allow me to send text files to my user. I am not
allowing them to view my directory. I am just downloading a file they
previously requested, which works some of the time.

Dim fs As FileStream
Dim strContentType As String
Dim strPath = "C:\My External\File Path\"
Dim strFileName As String = "TomsTest.t xt"
fs = File.Open(strPa th & strFileName, FileMode.Open)
Dim bytBytes(fs.Len gth) As Byte
fs.Read(bytByte s, 0, fs.Length)
fs.Close()
Response.AddHea der("Content-disposition", _
"attachment ; filename=" & strFileName)
Response.Conten tType = "applicatio n/octet-stream"
Response.Binary Write(bytBytes)
Response.End()

If I run this on an XP and the user has Automatic downloads of files
disabled, the user will get a blank page with all the text displaying on
it.

If it is enabled, I get the Save As prompt and allows the user to save the
file.

This can be confusing to the user. Is there a way for me to know if the
user will have a problem with the download?

This is not an automatic download, the user is actually pushing a button
saying he wants to download the file.

Thanks,

Tom

Mar 8 '06 #2

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

Similar topics

4
2165
by: Luke StClair | last post by:
Only marginally belonging in this newsgroup... but oh well. I've just started writing in python, and I want to make the files available on the web. So I did the standard <a href="mypath/myfile.py"> and not surprisingly, it displays like a webpage, but just the code. If I gzip it, and then link to the new file, it will download, but its so small I don't want it zipped. How can I make this into a downloadable file SIMPLY? The other...
2
2439
by: Bala | last post by:
Hi I am trying to download the PDF files from my webserver using ASP.Net. All my files are stored at F Drive on webserver. Like this F:\Main Folder\Sub Folder\Files\File1.pdf I am impersonating the domain user account and downloading the file, It seems the impersonate is got success, but its not download the file. Its simply downloading some junk pdf file instead of original file.
1
2083
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
0
1638
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops downloading with the error message: "the source file could not be read". And the error is not dependent on the size of the file, as I can download a file of 6MB but having problem with a file with 652KB. It always stops after 666880bytes. Thanks.
7
2545
by: Ehsan | last post by:
I foundd this code in ASPN Python Cookbook for downloading files in python but when it finished downloading files the files became corrupted and didn't open, the files in internet havn't any problem: def download(url,fileName): """Copy the contents of a file from a given URL to a local file. """ import urllib
0
9518
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
10430
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
10211
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
10159
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,...
1
7538
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
6776
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
5436
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
4111
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
3
2917
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.