[英]How can I Ask the user for a Path and then put the same Path as a Directory for a Directoryinfo?
您好,謝謝您。 我想做的是顯示目錄的所有文件。 目錄的路徑包含在代碼中。
我想要做的是詢問用戶一個目錄,然后使用該目錄的路徑代替:( ("*.*")
C#代碼
protected void ListFiles(object sender, EventArgs e)
{
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/"));
System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.*");
foreach (System.IO.FileInfo fi in fileNames)
{
listbox1.Items.Add(string.Format("{0} | {1} | {2} KB", fi.Name, fi.LastAccessTime, fi.Length));
}
}
ASP代碼
<asp:ListBox ID="listbox1" runat="server" OnLoad="ListFiles"Height="500" Width="600" Font-Bold="true"></asp:ListBox>
謝謝您的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.