If e.CommandName = "Download" Then Dim fst As New FileStream(Server.MapPath(e.CommandArgument), FileMode.Open) Dim fl As String = e.CommandArgument Dim file As String() = e.CommandArgument.ToString.Split(".") Dim extension As String = file(file.Length - 1) Dim bytBytes(fst.Length) As Byte 'read file byte by byte fst.Read(bytBytes, 0, fst.Length) fst.Close() Response.AddHeader("Content-disposition", "attachment; filename=" & fl) If extension = "docx" Then Response.ContentType = "application/vnd.ms-word.document" ElseIf extension = "pdf" Then Response.ContentType = "Application/pdf" ElseIf extension = "xls" Then Response.ContentType = "application/vnd.ms-excel" ElseIf extension = "xlsx" Then Response.ContentType = "application/vnd.ms-excel" ElseIf extension = "doc" Then Response.ContentType = "application/ms-word" End If 'write all the byte to newly created file Response.BinaryWrite(bytBytes) Response.End() End If
Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)