Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have written a program to generate two text files i.e to export data from sql server database to these Text files.But the problem is I am able to open only one text file.
But I want to download the two text files.

My code is below:

C#
Response.Clear();

if (!Directory.Exists(Path.GetDirectoryName(HttpContext.Current.Request.PhysicalApplicationPath.ToString()) + "\\Files ))
{
    Directory.CreateDirectory(Path.GetDirectoryName(HttpContext.Current.Request.PhysicalApplicationPath.ToString()) + "\\Files );
}

DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(HttpContext.Current.Request.PhysicalApplicationPath.ToString()) + "\\Files\\"  );

string file_name = directory + "filename" + ".txt";


System.IO.FileInfo file = new System.IO.FileInfo(file_name);
Response.AddHeader("Content-Disposition", "attachment; filename=" + strfilename );
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
Response.Redirect("");

Thanks in advance.
Posted
Updated 24-Jan-12 14:15pm
v6

1 solution

C#
string file_name = directory + "filename" + ".txt";

In the above line you have hard coded the file name as "filename.txt".
Is this ok?
 
Share this answer
 
Comments
neha427 25-Jan-12 8:12am    
Yes.Hardcoding is fine.
Sriram Chitturi 25-Jan-12 10:31am    
But then it is always going to read only one file called filename.txt.

Or am I missing something?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900