Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: luison en 24 Septiembre 2010, 21:57 pm



Título: Por qué no me funciona este codigo?
Publicado por: luison en 24 Septiembre 2010, 21:57 pm
Código
  1. Sub DownloadFile(ByVal virtualPath As String)
  2.        ' retrieve the physical path of the file to download, and create
  3.        ' a FileInfo object to read its properties
  4.        Dim FilePath As String = Server.MapPath(virtualPath)
  5.        Dim TargetFile As New System.IO.FileInfo(FilePath)
  6.  
  7.        ' clear the current output content from the buffer
  8.        Response.Clear()
  9.        ' add the header that specifies the default filename for the Download/
  10.        ' SaveAs dialog
  11.        Response.AddHeader("Content-Disposition", "attachment; filename=" + _
  12.         TargetFile.Name)
  13.        ' add the header that specifies the file size, so that the browser
  14.        ' can show the download progress
  15.        Response.AddHeader("Content-Length", TargetFile.Length.ToString())
  16.        ' specify that the response is a stream that cannot be read by the
  17.        ' client and must be downloaded
  18.        Response.ContentType = "application/octet-stream"
  19.        ' send the file stream to the client
  20.        Response.WriteFile(TargetFile.FullName)
  21.        ' stop the execution of this page
  22.        Response.End()
  23.    End Sub
  24.  
  25. +---------------------------------------------------------------+
  26. Lo que quiero lograr es que usuarios de mi sitio asp.net, puedan descargar archivos, pero hasta ahorita, ese codigo
  27. funciona del lado del servidor, cuando publico el sitio y lo intento, se descarga el archivo pero con contenido
  28. del front de la pagina donde hago click para descargar, o bien con caracteres raros.
  29.  
  30. Alguien sabe a que se debe que no me funcione del lado del cliente?
  31.  
  32. Gracias por sus comentarios.
  33.