Torna al Thread

Protected Function ConvertToKB(path As Object) As String Dim fi As New FileInfo(Server.MapPath(path)) Return String.Format("{0}KB", Math.Round(fi.Length / 1024, 2)) End Function Private Sub BindGrid() Dim DataDirectory As String = "~/File" Dim files() As FileInfo = New DirectoryInfo(Server.MapPath(DataDirectory)).GetFiles GridView2.DataSource = files GridView2.DataBind() End Sub Private Sub Downloadfile(ByVal fileName As String, ByVal FullFilePath As String) Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName) Response.TransmitFile(FullFilePath) Response.End() End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindGrid() End If MaintainScrollPositionOnPostBack = True End Sub Protected Sub GridView2_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim I As Int64 Dim S As String = "Fred" I = Convert.ToInt64(e.Row.Cells(1).Text) S = (I / 1024).ToString & " KB" e.Row.Cells(1).Text = S End If End Sub Protected Sub GridView2_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView2.PageIndexChanging GridView2.PageIndex = e.NewPageIndex BindGrid() End Sub Protected Sub GridView2_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView2.RowCommand If e.CommandName = "Download" Then Dim fileInfo() As String = e.CommandArgument.ToString().Split(";") Dim FileName As String = fileInfo(1) Dim FullPath As String = fileInfo(0) Downloadfile(FileName, FullPath) End If End Sub End Class
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5