string path = "~/Document/Introduction/团队管理制度/";
DirectoryInfo dirinfo = new DirectoryInfo(Server.MapPath(path));
FileInfo[] Files = dirinfo.GetFiles();
Array.Sort<FileInfo>(Files, new FIleLastTimeComparer());
//在页面上显示最近更新的两个文件的下载链接
for (int i = 0; i < 2; i++)
{
Literal literal = new Literal();
literal.Text = "</br>";
Panel1.Controls.Add(literal);//实现换行显示
HyperLink hypelink = new HyperLink();
hypelink.NavigateUrl = path + Files[i].Name;
hypelink.Text = Files[i].Name;
Panel1.Controls.Add(hypelink);
}
public class FIleLastTimeComparer : IComparer<FileInfo>
{
public int Compare(FileInfo x, FileInfo y)
{
return y.LastWriteTime.CompareTo(x.LastWriteTime);//递减
//return x.LastWriteTime.CompareTo(y.LastWriteTime);//递增
}
}
using System.IO;
就可以使用Array.Sort()方法来对其进行调用。当然,你也可以按创建时间来进行排序。
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <div style="padding-top:20px">
- <p style="font-size:12px;">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
- </div>