<%@ Page language="c#" src="ViewFiles.aspx.cs" AutoEventWireup="false" Inherits="ViewFiles" %>
<%--
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
public class ViewFiles : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.ListBox lstFiles;
protected System.Web.UI.WebControls.Button cmdRefresh;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label lblFileInfo;
protected System.Web.UI.WebControls.Button cmdDelete;
string ftpDirectory = System.Web.HttpContext.Current.Server.MapPath("yourfolderHere");//@"c:\Temp";
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
CreateFileList();
}
}
private void CreateFileList()
{
string[] fileList = Directory.GetFiles(ftpDirectory);
lstFiles.DataSource = fileList;
lstFiles.DataBind();
lblFileInfo.Text = "";
cmdDelete.Enabled = false;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lstFiles.SelectedIndexChanged += new System.EventHandler(this.lstFiles_SelectedIndexChanged);
this.cmdRefresh.Click += new System.EventHandler(this.cmdRefresh_Click);
this.cmdDelete.Click += new System.EventHandler(this.cmdDelete_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdRefresh_Click(object sender, System.EventArgs e)
{
CreateFileList();
}
private void cmdDelete_Click(object sender, System.EventArgs e)
{
// File.Delete(lstFiles.SelectedItem.Text);
//CreateFileList();
}
private void lstFiles_SelectedIndexChanged(object sender, System.EventArgs e)
{
string fileName = lstFiles.SelectedItem.Text;
lblFileInfo.Text = "" + fileName + "
";
lblFileInfo.Text += "Created : ";
lblFileInfo.Text += File.GetCreationTime(fileName).ToString();
lblFileInfo.Text += "
Last Accessed : ";
lblFileInfo.Text += File.GetLastAccessTime(fileName).ToString();
lblFileInfo.Text += "
";
FileAttributes attributes = File.GetAttributes(fileName);
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
lblFileInfo.Text += "This is a hidden file." + "
";
}
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
lblFileInfo.Text += "This is a read-only file." + "
";
}
if ((attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
{
cmdDelete.Enabled = true;
}
else
{
cmdDelete.Enabled = false;
}
}
}
--%>