Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Cannot redirect after HTTP headers have been sent.System.WebCannot redirect after HTTP headers have been sent.System.Web
Previous
 
Next
New Post
3/31/2009 4:14 AM
 

i want to download a file which user select from gridview, downloading is completing without problem but after download i want to refresh my page because i do  some changes in db .

 but when refresh.redirect() occure it give me error that 

Cannot redirect after HTTP headers have been sent.System.Web

 

following are my code to download file

 

FDownLoadFile(objAttachmentInfo.FileName)

Response.Redirect(EditUrl("ItemId", ItemId, "Anonymous", "&tab=4"), False)

 

Sub FDownLoadFile(ByVal fileName As String)
            Try
                Dim filePath As String = ConfigurationManager.AppSettings.Get("picUploadPath")
                Dim objFile As New System.IO.FileInfo(filePath + fileName)
                Dim objResponse As System.Web.HttpResponse = System.Web.HttpContext.Current.Response

                If objFile.Exists Then                   
                    objResponse.ClearContent()
                    objResponse.ClearHeaders()
                    objResponse.AppendHeader("content-disposition", "attachment; filename=""" & objFile.Name.ToString() & """")
                    objResponse.AppendHeader("Content-Length", objFile.Length.ToString())
                    objResponse.ContentType = DownloadFile.GetContentType(objFile.Extension.Replace(".", ""))
                    DownloadFile.WriteFile(objFile.FullName)
                Else
                    lb_attachment_status.Text = "File not exist."
                    Exit Sub
                End If
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)               
            End Try
        End Sub

 

 

 

 Imports System
Imports System.IO
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls


Namespace PLM.Modules.PLMAttachment
    ''' <summary>
    ''' Summary description for DownloadFile
    ''' </summary>
    '''
    Public Class DownloadFile
        Public Sub New()
            '
            ' TODO: Add constructor logic here
            '
        End Sub

        Public Shared Function GetContentType(ByVal extension As String) As String
            Dim contentType As String
            If extension.ToLower() = "txt" Then
                contentType = "text/plain"
            ElseIf extension.ToLower() = "htm" OrElse extension.ToLower() = "html" Then
                contentType = "text/html"
            ElseIf extension.ToLower() = "rtf" Then
                contentType = "text/richtext"
            ElseIf extension.ToLower() = "jpg" OrElse extension.ToLower() = "jpeg" Then
                contentType = "image/jpeg"
            ElseIf extension.ToLower() = "gif" Then
                contentType = "image/gif"
            ElseIf extension.ToLower() = "bmp" Then
                contentType = "image/bmp"
            ElseIf extension.ToLower() = "mpg" OrElse extension.ToLower() = "mpeg" Then
                contentType = "video/mpeg"
            ElseIf extension.ToLower() = "avi" Then
                contentType = "video/avi"
            ElseIf extension.ToLower() = "pdf" Then
                contentType = "application/pdf"
            ElseIf extension.ToLower() = "doc" OrElse extension.ToLower() = "dot" Then
                contentType = "application/msword"
            ElseIf extension.ToLower() = "csv" OrElse extension.ToLower() = "xls" OrElse extension.ToLower() = "xlt" Then
                contentType = "application/x-msexcel"
            Else
                contentType = "application/octet-stream"
            End If
            Return contentType
        End Function

        Public Shared Sub WriteFile(ByVal strFileName As String)
            Dim objResponse As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
            Dim objStream As System.IO.Stream = Nothing
            Try
                objStream = New System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
                WriteStream(objResponse, objStream)
                objStream.Close()                
            Catch ex As Exception
                objResponse.Write("Error : " & ex.Message)
            Finally
                If objStream Is Nothing Then
                    objStream.Close()
                End If
            End Try
        End Sub

        Private Shared Sub WriteStream(ByVal objResponse As HttpResponse, ByVal objStream As Stream)
            Dim bytBuffer As Byte() = New Byte(9999) {}
            Dim intLength As Integer
            Dim lngDataToRead As Long
            Try
                lngDataToRead = objStream.Length
                While lngDataToRead > 0
                    If objResponse.IsClientConnected Then
                        intLength = objStream.Read(bytBuffer, 0, 10000)
                        objResponse.OutputStream.Write(bytBuffer, 0, intLength)
                        objResponse.Flush()
                        ' TODO: NotImplemented statement: ICSharpCode.SharpRefactory.Parser.AST.VB.ReDimStatement
                        lngDataToRead = lngDataToRead - intLength
                    Else
                        lngDataToRead = -1
                    End If
                End While
            Catch ex As Exception
                objResponse.Write("Error : " & ex.Message)
            Finally
                If objStream Is Nothing Then
                    objStream.Close()
                    objResponse.Flush()
                End If
            End Try
        End Sub

    End Class
End Namespace

 

if i write refresh.redirect() line before download file, downloading without error but not refresh.

 

Can anybody give me solution for this problem

Thanks Advance

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Cannot redirect after HTTP headers have been sent.System.WebCannot redirect after HTTP headers have been sent.System.Web


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out