.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How can I download an Excel file saved on the same server as an asp.Net website?

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net


I able to successfully see all the Excel files in the given folder using the datagrid and code below. Now I would like to be able to click the link to the file, or add a button, to get a download file dialog box. Can someone please help me.



<asp:datagrid id="FileGrid" runat="server" 
    AutoGenerateColumns="False" AllowSorting="True">
        <asp:TemplateColumn HeaderText="File" >
                <asp:HyperLink id="systemLink" runat="server" 
                NavigateUrl='<%# DataBinder.Eval(Container, "DataItem") %>'
                Text='<%# DataBinder.Eval(Container, "DataItem") %>' />
        <asp:BoundColumn DataField="Length" HeaderText="File Size" />
        <asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Modified" />


Imports System.IO

Partial Class pageclass

View Complete Post

More Related Resource Links

Problem download file from SQL Server


Hello everyone. I am having an issue downloading files that I have store in SQL Server. I have no problem in a WinForm. What am I doing wrong in my code?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim sch As New clsReport
        Dim fileData As New clsReport.Letter
        fileData = sch.DownloadLetter(Session("LetterID"))
        Dim ms As System.IO.MemoryStream = fileData.fil

        Dim fil As Byte() = ms.ToArray
        Dim nam As String = fileData.name
        Dim ext As String = fileData.ext
        If Not fil Is Nothing Then
                ' Response.Clear()
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + nam & "." & ext)
                ' Response.AddHeader("Content-Disposition", nam & "." & ext)
                Response.AddHeader("Content-Length", fil.Length.ToString)
                Response.ContentType = "Application/octet-stream"
                Response.Buffer = True
            Catch ex As Exception
            End Try

        End If

    End Su

Insert Excel Data via File Upload into sql server database???

Hi all, I have requirement that User can Upload the Excel Sheet Data to sql server Database at once. How i do that Any Article or hint is apperciated.   Regards 

Server drafts location not being saved Excel 2007

Hi, I have problem with "Server drafts location" not being remembered. And my "Server drafts location on this computer" button is not even checked but I still get the message: "The server drafts location you entered for offline editing is not valid or you do not have permission to access that location. Please specify a location on your local computer" Even if I change and choose a place for this it renders this message as soon as I for example "Adjusted List". Every thing I change in "Excel Options" renders the above message. I have full control over the "Application data" folder as well. Please see if you can help out since this is really giving me trouble in my daily work. I have Microsoft Windows XP professional sp 3 and Office 2007 latest sp. Thanks in advance! Mari

Client download .csv file from server using Response.TransmitFile

I am using the code below to enable clients to download a .csv file from my server.The problem I am having is that when the file is saved to the client computer the file name is prefixed and suffixed with an underscore which leads to a file type of .csv_ which is obviously not a recognised file type.How can I strip the underscores from the file name at the transmit stage?        Dim FileName As String = LstBox1.SelectedItem.ToString        Dim FilePath As String = "~/temp" & FileName        Response.Clear()        Response.ContentType = "text/csv"        Response.AddHeader("Content-Disposition", "attachment; filename=\" & FileName & "\")        Response.TransmitFile(FilePath)        Response.End() 

Force File Download on a Remote File Server

Hi!I'm trying to force a large (200+ MB) file to download that's on a remote server. The problem is that I can't use the "WriteFile()" function, since I'm not using a virtual path.Then, when I try:Response.AppendHeader("content-disposition",                 "attachment; filename=" + name);Response.AppendHeader("content-disposition", "attachment; filename=" + name);I get a file that has the correct name and extension, but is 0KB. Can someone please help me?!Thanks!-Eric

Download .xlsx file from server

Hi, Iv created a web application using vb.net 2005. Its working fine and running fine on the server (Microsoft Server 2003). The problem i have is to dowload a file from the same server using vb.net. I tried using this code but it gives me a : "is not a virtual path" error. Response.ContentType = "file/xlsx" Response.AppendHeader( Response.TransmitFile( Response.End()"Content-Disposition", "attachment; filename=AllReports.xlsx")".xlsx") Please help, im way overdue with this. Thank.

importing excel file into sql server 2005 in asp .net using c#

Dear friends i want to import excel file into sql server 2005 in asp .net using c# can anyone help me? rgds,RK

can I use SQL Server to export an excel file directly?


I just want to know except use owc

can we use SQL Server to export excel file ?

if it can be , how to do? thanks alot

Import Excel File in SQL Server


Dear all,

I have to create one page where user will upload the excel file in SQl Server and system should check following things

1.Sheet Name should be always sheet1

2.System should check the column names

3.System should show the message that these many rows has been loaded



Import Excel-File (OPENROWSET) on x64 SQL Server


Hi, recently I encountered the following problem:

I tried to execute a stored procedure on the newly installed SQL 2005 Server (now on x64 Win Server 2003) which imports an Excel-File into a DB table.

We use OPENROWSET to access the Excel data. But I recognized this is dependent on Jet OLE DB which seems is not available for x64 windows.


Is there another way to import excel data using a stored procedure.


thank you in advance, rene

Download an XML File to the IIS server, not to the client


Hey guys,

I'm trying to do the following in ASP.NET (with c#):

1. On page Load, download an XML file from a different website to the IIS server, in a subdirectory of the application directory called "downloadedFiles"

I know that WebClient.DownloadFile() can download a file, but this only seems to download the file to the client's machine. I am interested in downloading it to the actual IIS server (so that it can be utilized throughout the lifetime of more than one session). Does anyone know how this could be performed?

Specifically, I'm trying to download an XML file from a website (as an example: http://api.twitter.com/1/statuses/followers/CiscoSystems.xml). How could I download that XML file onto my actual IIS server?

Thanks a ton for any help

download ms access table to an excel file


Is there a way to give users the capability to download an on-line table produced via gridview to an excel file (other than by copy/paste)?

Import Excel File to Sql Server on a 64 bit machine


I need to import Excel (xls - 2003-2007) data into a Sql Server 2008 database. Both the Excel file and the database live on a Windows Server 2003 R2 sp2 64 bit machine.  I’m fine with it running in 32 bit mode but it all needs to happen on the same server. Also, I would like it to run in T-Sql but as a fallback we can do this in SSIS.

My T-Sql code which runs fine on a 32 bit machine is as follows:

SELECT * Into #TempTable From OpenRowSet('Microsoft.Jet.Oledb.4.0','Excel 8.0;Database=\\Servername\Folder\filename.xls;HDR=NO;IMEX=1', 'select * from [Main$]')


On the 64 bit server:

Download audio file from server


string url = string.Empty;

string title = string.Empty;

//full file path should be assigned to url

//file name with format should be assigned to title    

url = "http://abc.com/abc.mp3";     

title = "abc.mp3.mp3";

WebClient wc = new WebClient();
byte[] byteData;
Response.BinaryWrite(byteData= wc.DownloadData(@url));

linked server to excel file



I,m trying to make a linked server connection to an excel 2007 file. I have SQL server 2008 R2 and i have used the code below. When i test the connection to the linked server it works but i still only get this error (se below). I also tried different security settings such as Not be made, Be made without using a security content, Be made using the logins current security content and be made using this security content Remote login = Admin, with password (password left blank). someone and ideas on how to solve this?



Msg 7399, Level 16, State 1, Line 1

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "XLFile" reported an error. The provider did not give any information about the error.

Msg 7330, Level 16, State 2, Line 1

Cannot fetch a row from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "XLFile"

EXEC sp_addlinkedserver
@server = 'XLFile', 
@srvproduct='ACE 12.0',
@datasrc= 'C:\File2.xlsx',
@provstr='EXCEL 12.0; Hdr=Yes';

Select *
FROM XLFile...[Sheet1$]

Arne Olsson

File corrupt issue with SQL Server Express 2008 Download

I have tried to download SQL Server Express 2008 with advanced services a several times from different locations across the MS web site.  I keep getting a File Corrupt error when extracting "owc11sp1.msp."  I have tried several different computers and following the steps directly.  I can not perform a web install on the machine that will host the SQL server, so that option is out.  Does anyone know where I can get a copy of this that actually works?

I tried downloading it from here:

Write excel file on server to transfer to user, including colours


I want to export a large amount of data to an excel file (30,000 plus). This is no problem. The problem is that, one of the columns needs to be coloured green according to the data within it.

For example, the colour contains percentages, and when the percentage is over 70%, then the cell needs to be green.

I can do this easily using a Datagrid/Gridview. However, because of the amount of data, my server is crashing with a SystemOutOfMemory exception.

What I would like to do is use a tool to write the data to an excel file, and then transfer the file. Is this possible?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend