- 註冊時間
- 2010-7-12
- 最後登錄
- 2024-5-30
- 主題
- 查看
- 積分
- 5
- 閱讀權限
- 15
- 文章
- 6
- 相冊
- 0
- 日誌
- 0
狀態︰
離線
|
本帖最後由 t2311y 於 2012-12-16 10:43 編輯
Protected Sub Button_list_dir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button_list_dir.Click
Dim dir_current_path As String
Dim dir_current_root_path As String
Dim folder, folder_names(), sub_dir As DirectoryInfo
Dim File_Names(), sub_file As FileInfo
Dim file_name_url As String = ""
Dim row As TableRow
Dim cell_1, cell_2, cell_3, cell_4 As TableCell
Dim url As String = ""
Dim encode_url As String
dir_current_path = file_location & message_current_dir.Text
dir_current_root_path = Server.MapPath(dir_current_path)
folder = New DirectoryInfo(dir_current_root_path)
folder_names = folder.GetDirectories()
File_Names = folder.GetFiles()
row = New TableRow
cell_1 = New TableCell()
cell_2 = New TableCell()
cell_3 = New TableCell()
cell_4 = New TableCell()
cell_1.Text = "檔案名稱"
row.Cells.Add(cell_1)
row.Cells(0).Width = row.Cells(1).Width.Pixel(200)
row.Cells(0).HorizontalAlign = HorizontalAlign.Center
row.Cells(0).BackColor = row.Cells(0).BackColor.LightCyan
cell_2.Text = "檔案大小"
row.Cells.Add(cell_2)
row.Cells(1).Width = row.Cells(1).Width.Pixel(200)
row.Cells(1).HorizontalAlign = HorizontalAlign.Center
row.Cells(1).BackColor = row.Cells(1).BackColor.LightCyan
cell_3.Text = "檔案日期"
row.Cells.Add(cell_3)
row.Cells(2).Width = row.Cells(1).Width.Pixel(200)
row.Cells(2).HorizontalAlign = HorizontalAlign.Center
row.Cells(2).BackColor = row.Cells(2).BackColor.LightCyan
cell_2.Text = "檔案大小"
row.Cells.Add(cell_4)
row.Cells(3).Width = row.Cells(1).Width.Pixel(200)
row.Cells(3).HorizontalAlign = HorizontalAlign.Center
row.Cells(3).BackColor = row.Cells(2).BackColor.LightCyan
Table_list.Rows.Add(row)
For Each sub_dir In folder_names
row = New TableRow()
cell_1 = New TableCell()
cell_2 = New TableCell()
cell_3 = New TableCell()
cell_4 = New TableCell()
url = message_current_dir.Text & sub_dir.Name
encode_url = Server.UrlPathEncode(url.ToString)
cell_1.Text = "<a href=default.aspx?dir_name=" & encode_url & ">" & sub_dir.Name
row.Cells.Add(cell_1)
cell_2.Text = "<資料夾>"
row.Cells.Add(cell_2)
row.Cells(1).HorizontalAlign = HorizontalAlign.Right
cell_3.Text = sub_dir.LastWriteTime
row.Cells.Add(cell_3)
row.Cells(2).HorizontalAlign = HorizontalAlign.Right
cell_4.Text = "<a target=_black href=dir_rename.aspx?dir_name=" & encode_url & ">更名" & "|" & "<a target=_black href=dir_delete.aspx?dir_name=" & encode_url & ">刪除"
row.Cells.Add(cell_4)
row.Cells(3).HorizontalAlign = HorizontalAlign.Center
Table_list.Rows.Add(row)
Next
For Each sub_file In File_Names
row = New TableRow()
cell_1 = New TableCell()
cell_2 = New TableCell()
cell_3 = New TableCell()
cell_4 = New TableCell()
url = message_current_dir.Text & sub_file.Name
encode_url = Server.UrlEncode(url.ToString)
cell_1.Text = "<a href=get_file.aspx?name=" & encode_url & ">" & sub_file.Name
row.Cells.Add(cell_1)
cell_2.Text = sub_file.Length
cell_2.Text = sub_file.Length.ToString("###,###")
row.Cells(1).HorizontalAlign = HorizontalAlign.Right
cell_3.Text = sub_file.LastWriteTime
row.Cells.Add(cell_3)
row.Cells(2).HorizontalAlign = HorizontalAlign.Right
cell_4.Text = "<a target=_black href=file_rename.aspx?name=" & encode_url & ">更名" & "|" & "<a target=_black href=file_delete.aspx?name=" & encode_url & ">刪除"
row.Cells.Add(cell_4)
row.Cells(3).HorizontalAlign = HorizontalAlign.Center
Table_list.Rows.Add(row)
Next
Table_list.Visible = True
End Sub
End Class
這是我的程式~
行 156: cell_2.Text = sub_file.Length
行 157: cell_2.Text = sub_file.Length.ToString("###,###")
行 158: row.Cells(1).HorizontalAlign = HorizontalAlign.Right
行 159: cell_3.Text = sub_file.LastWriteTime
行 160: row.Cells.Add(cell_3)
這第158行跳出錯誤~請問該如何修改
這是一個目錄
按顯示資料夾內容假如裡面沒東西就跑出空資料夾
但假如一放東西就跳出
指定的引數超出有效值的範圍。參數名稱: index |
|