Hi,
i'm using asp.net 1.1 for my project. I have a written a c# code where the user can upload his files through the file upload component which gets uploaded to the specified path in a local disk and these files are viewed on the user screen application using the concept of fetching files from the local drive.
I have taken a table to store these files in 1 column and in the other column i have given hyperlinks to download the files.
I have actually tried to do newsletter archiving, but the files get displayed depending on the alphabetical order which i dont want. I want them to be listed in the latest upload pattern depending on the date and time which i am not able to code efficiently.
Can anyone please please help me out with this.......please...
Here is the code i have used.....
using System.IO;
namespace FileDownLoadExample
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table Table1;
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["filename"]!= null)
{
DownLoadFile(Request.QueryString"filename"]);
}
if(!IsPostBack)
{
LoadFileInfo();
}
}
private void LoadFileInfo()
{
DirectoryInfo dir = new DirectoryInfo("c:/uploads");
FileInfo[] file_info_array = dir.GetFiles();
foreach(FileInfo file_info in file_info_array)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
cell1.Text = file_info.Name;
HyperLink link = new HyperLink();
link.Text = "Download";
link.NavigateUrl ="./WebForm1.aspx?filename="+file_info.Name;
cell2.Controls.Add(link);
row.Controls.Add(cell1);
row.Controls.Add(cell2);
Table1.Controls.Add(row);
}
}
private void DownLoadFile(string filename)
{
try
{
Response.Clear();
string Filename = Request.QueryString["filename"];
string downloadPath = "c:/uploads/"+Filename;
Response.ContentType ="application/octet-stream";
Response.AddHeader("Content-Disposition","attachment; filename="+Filename);
Response.TransmitFile(downloadPath);
}
catch(HttpException err)
{
Response.Write(err.ToString());
}
}