Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP.Net/VB.Net - How to prompt download of a file in physical path on server?

Posted on 2008-11-19
3
Medium Priority
?
781 Views
Last Modified: 2013-11-05
I have zip files stored in a path that is in a physical path referenced in my web config.  I can't use a virtual directory because we will be on a web farm.  They are zip files that I will have the name in a datagrid which I want to be a linkbutton that can prompt the download of the file for the client machine.  Any idea how I can do that.
0
Comment
Question by:sbornstein2
3 Comments
 
LVL 16

Expert Comment

by:TSmooth
ID: 22995734
Create a generic HttpHandler and open the file for read within that and write it to the response stream. Your link button would then point to something ilke "MyHttpHandler.ashx?FileID=123".
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22998393
Alternatively, you can use Response stream to force the file download dialog to display. Here is how:
1. Make sure ASPNET has read access to the file or folder.
2. In the event handler that handles the click of the LinkButton, do something like this (assume you already retrieved the file path from web.config file):

Dim fi As System.IO.FileInfo = New FileInfo(path)
If (fi.Exists) Then
	Response.Clear()
	Response.AddHeader("Content-Disposition", "attachment;filename=" & fi.Name)
	Response.ContentType = "application/octstream"
	Response.AddHeader("Content-Length", fi.Length)
	Response.TransmitFile(path)
	Response.Flush()
	Response.Clear()
End If

Open in new window

0
 

Author Closing Comment

by:sbornstein2
ID: 31518307
this is perfect
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question