Amigos,
Por favor necesito de su ayuda, no se que sucede pero necesito abrir un archivo TXT generado en una pagina ASP, les dejo el codigo que estoy utilizando. MUCHAS GRACIAS DE ANTEMANO.
Protected Sub ibtnTextoGR_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnTextoGR.Click
Try
Dim objEntidadBE As New RankingBE
Dim objEntidadBC As New ConvenioBC
objEntidadBE = GetEntidad()
Dim dt As Data.DataTable
dt = objEntidadBC.GETLISTADGPP(objEntidadBE, "")
If dt.Rows.Count > 0 Then
Dim FILE_NAME As String = Server.MapPath("MyFileGR.txt")
'Si existe el archivo se borra
If File.Exists(FILE_NAME) Then
File.Delete(FILE_NAME)
End If
'Crea el archivo TXT
Dim sr As StreamWriter = File.CreateText(FILE_NAME)
'Escribo en el archivo TXT
For I As Integer = 0 To dt.Rows.Count - 1
Dim TipoGOB As String = dt.Rows.Item(I)("TIPO_GOBIERNO")
Dim NumeroCONV As String = dt.Rows.Item(I)("NUM_CONVENIO")
sr.WriteLine(TipoGOB & " " & NumeroCONV)
Next
'Cierro el archivo generado TXT
sr.Close()
'---- PROCEDIMIENTO PARA CARGAR EL ARCHIVO TXT GENERADO -----
'Abrir el Archivo Generado
Dim objStream As System.IO.Stream = New FileStream(FILE_NAME, FileMode.Open)
Dim FileSize As Long
FileSize = objStream.Length
Dim Buffer(CInt(FileSize)) As Byte
objStream.Read(Buffer, 0, CInt(FileSize))
objStream.Close()
'Response.Clear()
Response.BufferOutput = True
Response.ContentType = "text/plain"
'Abre el archivo a GRABAR pero en formato ASP ó HTML y no en TXT
Response.AppendHeader("content-disposition", "attachment; Server.MapPath(FILE_NAME)")
Response.BinaryWrite(Buffer)
Response.End()
End If
Catch ex As Exception
ScriptManager.RegisterClientScriptBlock(udpDatos, udpDatos.GetType, "Error", "alert('Error al exportar los datos')", True)
End Try
End Sub