Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.

How to save a file on client side?

create an asp page "Download.aspx"

In Design side just have

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Download.aspx.cs" Inherits="Download" ContentType="Text/xml" %>

Code on CS side


string strFile= "";

if (Request.QueryString.HasKeys())


if ((Request.QueryString["vid"] != null) || Request.QueryString["vid"].ToString().Equals(""))  // where vid is your querystiing


strFile= Request.QueryString["vid"].ToString();






this.EnableViewState = false;

Response.ContentType = "text/xml";

string Filename = System.Web.HttpContext.Current.Server.MapPath("test.xml");// your file name

//Filename = Filename + certId + ".vcf";


Response.Buffer = true;

Response.AddHeader("Content-Disposition", "attachment; filename=" + Filename );


catch (Exception ex) { Response.Write(ex.ToString()); }




Posted on Wednesday, January 24, 2007 11:04 AM | Back to top

Comments on this post: How to save a file on client side

# re: How to save a file on client side
Requesting Gravatar...
My problem is that i want the client has filled data in resp. controls(textbox) that data should be saved on in text file in client system (i.e. data should be saved on client side in using c#.)
Left by vivek gupta on Mar 02, 2009 10:26 PM

# re: How to save a file on client side using java or javascript
Requesting Gravatar...
Hii friend,
I got a code for Exporting data from MYSQL to Excel Sheet... wherein, it contains a method called generatexls(String tablename, String filename)

In the Main part of the program we are giving like,

where student is a tablename, and we are giving the path of the file to be stored....

Till now it's ok but when we deploy it in the server & when we need to export it, it is saving in C drive of server...

Instead it should ask me to save wherever the user needs(like a **save as option**) will u please See the code and try to modify it... I need it very urgently...


package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class MysqlToXls {

private Connection connection = null;

public MysqlToXls(String database, String user, String password)
throws ClassNotFoundException, SQLException {

// Create MySQL database connection

String url = "jdbc:mysql://localhost:3306/" + database;
connection = DriverManager.getConnection(url, user, password);

@SuppressWarnings({ "deprecation" })
public void generateXls(String tablename, String filename)
throws SQLException, FileNotFoundException, IOException {

// Create new Excel workbook and sheet
HSSFWorkbook xlsWorkbook = new HSSFWorkbook();
HSSFSheet xlsSheet = xlsWorkbook.createSheet();
short rowIndex = 0;

// Execute SQL query
PreparedStatement stmt = connection.prepareStatement("select * from " + tablename);
ResultSet rs = stmt.executeQuery();

// Get the list of column names and store them as the first
// row of the spreadsheet.
ResultSetMetaData colInfo = rs.getMetaData();
List<String> colNames = new ArrayList<String>();
HSSFRow titleRow = xlsSheet.createRow(rowIndex++);

for (int i = 1; i <= colInfo.getColumnCount(); i++) {

titleRow.createCell((short) (i-1)).setCellValue(
new HSSFRichTextString(colInfo.getColumnName(i)));

xlsSheet.setColumnWidth((short) (i-1), (short) 6000);

// Save all the data from the database table rows
while ( {
HSSFRow dataRow = xlsSheet.createRow(rowIndex++);
short colIndex = 0;
for (String colName : colNames) {
new HSSFRichTextString(rs.getString(colName)));

// Write to disk
xlsWorkbook.write(new FileOutputStream(filename));

// Close database connection
public void close() throws SQLException {

public static void main(String[] args) {
try {
MysqlToXls mysqlToXls = new MysqlToXls("lportal61rc1", "root", "root");
mysqlToXls.generateXls("student", "C:\\Temp\\student.xls");
System.out.println("Excel File Saved");
} catch (Exception e) {
Left by Raghu on Mar 21, 2012 6:03 PM

Your comment:
 (will show your gravatar)

Copyright © Gaurav Taneja | Powered by: