0
下午所有,asp.net文件上傳(如何創建超鏈接載的文件,在我的GridView中顯示)
我有我已經完成了我的視覺正在開發一個網站一個簡單的文件上傳教程工作室2010.
我只是想通過使該文件鏈接到該文檔在gridview中顯示上傳的文件的網格視圖。這將使用戶能夠通過按下gridview中的鏈接來查看文件,然後上傳文件並查看文件。
這是到目前爲止我的代碼...
<form id="form1" runat="server">
<div>
<table style="width: 90%">
<tr>
<td style="width: 100px"> Single File Upload:<br />
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="buttonUpload" runat="server" Text="Upload" /><br />
<br />
<asp:GridView ID="UploadedFiles" DataSource="<%# GetUploadList() %>" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
這裏是.VB頁
Partial Class test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
UploadedFiles.DataBind()
End If
End Sub
Protected Function GetUploadList() As String()
Dim folder As String = Server.MapPath("~/Uploads")
Dim files() As String = Directory.GetFiles(folder)
Dim fileNames(files.Length - 1) As String
Array.Sort(files)
For i As Integer = 0 To files.Length - 1
fileNames(i) = Path.GetFileName(files(i))
Next
Return fileNames
End Function
Protected Sub UploadThisFile(ByVal upload As FileUpload)
If upload.HasFile Then
Dim theFileName As String = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName)
If File.Exists(theFileName) Then
File.Delete(theFileName)
End If
upload.SaveAs(theFileName)
End If
End Sub
Protected Sub buttonUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonUpload.Click
UploadThisFile(FileUpload1)
UploadedFiles.DataBind()
End Sub
End Class
林也不太清楚如何添加一些額外的代碼到Protected Sub UploadThisFile(ByVal upload As FileUpload)
節。
任何幫助,使上載文件中可用的這個靜態列表可以保存到一個鏈接到這些單個文檔的列表中,非常受歡迎。
提前許多感謝, 貝蒂
很多感謝您的快速響應。我使用代碼行來生成文件名上的鏈接,這是一種享受。非常感謝您的時間。 – Betty
貝蒂非常歡迎你! – CoderRoller