这里帖上,
如果是做成Custom Control的结果..(其实恢复控件在CreateChildControls里做更好)
(但是更好的是在LoadViewState后做)namespace LWSampleCS
{
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 FilesControl : Control,INamingContainer
{
Button BtnRefresh;
Button BtnUpload;
HtmlInputFile InputFile; //Create - or Restore
protected override void CreateChildControls()
{
base.CreateChildControls(); if(Files==null)
{
ResetTable();
}
else
{
FillTable();
}
} public void FillFiles()
{
string dir=Context.Server.MapPath("Files");
if(!Directory.Exists(dir))
Directory.CreateDirectory(dir);
Files=Directory.GetFiles(dir);
} public string[] Files
{
get
{
return (string[])ViewState["Files"];
}
set
{
ViewState["Files"]=value;
}
} public void ResetTable()
{
FillFiles();
Controls.Clear();
ClearChildViewState();
FillTable();
} public void RestoreTable()
{
Controls.Clear();
ClearChildViewState();
FillTable();
} public void FillTable()
{
Table table=new Table();
table.Attributes["border"]="1";
table.Style["border-collapse"]="collapse";
table.CellPadding=2;
table.CellSpacing=0;
table.Width=Unit.Percentage(100); TableRow hrow=new TableRow(); TableCell hcell;
hcell=new TableCell();
hcell.Text="FileName";
hrow.Cells.Add(hcell);
hcell=new TableCell();
hcell.Text="CreationTime";
hrow.Cells.Add(hcell);
hcell=new TableCell();
hcell.Text="Delete";
hrow.Cells.Add(hcell); table.Rows.Add(hrow); foreach(string file in Files)
{
TableRow row=new TableRow();
TableCell cell; //FileName
cell=new TableCell();
cell.Text=file;
row.Cells.Add(cell); //CreationTime
cell=new TableCell();
cell.Text=File.GetCreationTime(file).ToString("yyyy-MM-dd HH:mm:ss");
row.Cells.Add(cell); //Delete
cell=new TableCell(); row.Cells.Add(cell); Button ButtonDelete=new Button();
ButtonDelete.Click+=new EventHandler(ButtonDelete_Click);
ButtonDelete.Text="Delete";
ButtonDelete.Attributes["filename"]=file;
cell.Controls.Add(ButtonDelete); table.Rows.Add(row);
} //this
Controls.Add(table); BtnRefresh=new Button();
BtnRefresh.Click+=new EventHandler(BtnRefresh_Click);
BtnRefresh.Text="Refresh";
Controls.Add(BtnRefresh); InputFile=new HtmlInputFile();
Controls.Add(InputFile); BtnUpload=new Button();
BtnUpload.Click+=new EventHandler(BtnUpload_Click);
BtnUpload.Text="Upload";
Controls.Add(BtnUpload);
} private void BtnRefresh_Click(object sender, EventArgs e)
{
ResetTable();
BtnRefresh.Text="Refresh @ "+DateTime.Now.ToLongTimeString();
} private void BtnUpload_Click(object sender, EventArgs e)
{
if(InputFile.PostedFile.FileName!="")
{
string newpath=Path.Combine(Context.Server.MapPath("Files"),Path.GetFileName(InputFile.PostedFile.FileName));
byte[] buf;
using(Stream stream=InputFile.PostedFile.InputStream)
{
buf=new byte[stream.Length];
stream.Read(buf,0,buf.Length);
}
using(FileStream fs=new FileStream(newpath,FileMode.Create,FileAccess.Write))
{
fs.Write(buf,0,buf.Length);
}
ResetTable();
BtnUpload.Text="Upload @ "+DateTime.Now.ToLongTimeString();
}
else
{
BtnUpload.Text="File? @ "+DateTime.Now.ToLongTimeString();
}
} private void ButtonDelete_Click(object sender, EventArgs e)
{
Button Btn=(Button)sender;
File.Delete(Btn.Attributes["filename"]);
ResetTable();
}
}
}

解决方案 »

  1.   

    to: saucer(思归) 
    上面算是两个例子了.
    如果把创建表格那段缩短,并且稍微减少函数的数量
    那应该算简单了吧?
    -----
    不过那两个例子都有问题。
    吃完饭后传个好点的上来.
      

  2.   

    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----前面两个例子有点问题.这里下载最后的版本.http://www.lostinet.com/files/FileManager.rar----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
    ----最新更新----
      

  3.   

    LWS控件的dll在哪儿?怎么引用啊?
      

  4.   

    大家要试试啊。to: tomsoncat(可以包含中文字符) LWS引用的就是那几个CS文件里的东西啊。MyPanel在FileManager.aspx.cs最下面.
      

  5.   

    学习,偶也碰到过这种情况,没成功。MARK