J
John Wright
First problem. I receive a byte array that is a word document that I
reconstruct in the response buffer, no problem. What I want to happen is to
display this Word document in a new browser window not in word. Here is the
code I have tried so far (complete code at end of post):
Response.AddHeader("Content-Disposition", "attachment; filename=" + name)
This code opens a dialog box and passes the document to my local word
instance and opens it there. This is what we don't want.
Response.AddHeader("Content-Disposition", "inline; filename=" + name)
This code will open the document in the browser but not in a new window like
we want. How can we get a new browser window to open and display the
document.
Second Problem.
I have a panel that is hidden that I want to display after flushing the
Response object and hidding another panel. The code I use is:
AckPanel.Visible = True
ReadPanel.Visible = False
Stepping through the code, these lines execute, but the panel does not hide
nor show. I have tried putting these in various locations without success.
How can I show and hide the panels I need after flushing the response
object?
Thank you.
(Code for both problems)
Protected Sub btnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCopy.Click
Try
Dim ws As New ws.Service
Dim proc() As Byte
Dim name() As String
Dim msg As String = "" 'message from webservice
name = Split(ddlProcs.SelectedValue, ".")
proc = ws.GetFile(name(0), name(1), msg)
'My.Computer.FileSystem.WriteAllBytes(My.Application.Info.DirectoryPath
& "\" & docname, document, False)
If msg = "Found File" Then
AckPanel.Visible = True
ReadPanel.Visible = False
ShowProc(proc, ddlProcs.SelectedValue)
Else
Me.lblError.Text = msg
lblError.Visible = True
End If
Catch ex As Exception
Me.lblError.Text = Err.Description
lblError.Visible = True
Finally
AckPanel.Visible = True
ReadPanel.Visible = False
End Try
End Sub
Protected Sub ShowProc(ByVal Proc() As Byte, ByVal name As String)
Try
Using ms As New IO.MemoryStream(Proc)
Dim dataLengthToRead As Long = ms.Length
Dim blockSize As Integer = IIf(dataLengthToRead >= 5000,
5000, CInt(dataLengthToRead))
Dim buffer As Byte() = New Byte(dataLengthToRead - 1) {}
Response.Clear()
' Clear the content of the response
Response.ClearContent()
Response.ClearHeaders()
' Buffer response so that page is sent
' after processing is complete.
Response.BufferOutput = True
' Add the file name and attachment,
' which will force the open/cance/save dialog to show, to
the header
Response.AddHeader("Content-Disposition", "attachment;
filename=" + name)
' bypass the Open/Save/Cancel dialog
'Response.AddHeader("Content-Disposition", "inline;
filename=" + name)
' Add the file size into the response header
Response.AddHeader("Content-Length", Proc.Length.ToString())
' Set the ContentType
Response.ContentType = "application/octet-stream"
' Write the document into the response
While dataLengthToRead > 0 AndAlso
Response.IsClientConnected
Dim lengthRead As Int32 = ms.Read(buffer, 0, blockSize)
Response.OutputStream.Write(buffer, 0, lengthRead)
'Response.Flush(); // do not flush since BufferOutput =
true
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Flush()
Response.Close()
End Using
' End the response
'Response.End()
AckPanel.Visible = True
ReadPanel.Visible = False
Catch ex As Exception
End Try
End Sub
reconstruct in the response buffer, no problem. What I want to happen is to
display this Word document in a new browser window not in word. Here is the
code I have tried so far (complete code at end of post):
Response.AddHeader("Content-Disposition", "attachment; filename=" + name)
This code opens a dialog box and passes the document to my local word
instance and opens it there. This is what we don't want.
Response.AddHeader("Content-Disposition", "inline; filename=" + name)
This code will open the document in the browser but not in a new window like
we want. How can we get a new browser window to open and display the
document.
Second Problem.
I have a panel that is hidden that I want to display after flushing the
Response object and hidding another panel. The code I use is:
AckPanel.Visible = True
ReadPanel.Visible = False
Stepping through the code, these lines execute, but the panel does not hide
nor show. I have tried putting these in various locations without success.
How can I show and hide the panels I need after flushing the response
object?
Thank you.
(Code for both problems)
Protected Sub btnCopy_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCopy.Click
Try
Dim ws As New ws.Service
Dim proc() As Byte
Dim name() As String
Dim msg As String = "" 'message from webservice
name = Split(ddlProcs.SelectedValue, ".")
proc = ws.GetFile(name(0), name(1), msg)
'My.Computer.FileSystem.WriteAllBytes(My.Application.Info.DirectoryPath
& "\" & docname, document, False)
If msg = "Found File" Then
AckPanel.Visible = True
ReadPanel.Visible = False
ShowProc(proc, ddlProcs.SelectedValue)
Else
Me.lblError.Text = msg
lblError.Visible = True
End If
Catch ex As Exception
Me.lblError.Text = Err.Description
lblError.Visible = True
Finally
AckPanel.Visible = True
ReadPanel.Visible = False
End Try
End Sub
Protected Sub ShowProc(ByVal Proc() As Byte, ByVal name As String)
Try
Using ms As New IO.MemoryStream(Proc)
Dim dataLengthToRead As Long = ms.Length
Dim blockSize As Integer = IIf(dataLengthToRead >= 5000,
5000, CInt(dataLengthToRead))
Dim buffer As Byte() = New Byte(dataLengthToRead - 1) {}
Response.Clear()
' Clear the content of the response
Response.ClearContent()
Response.ClearHeaders()
' Buffer response so that page is sent
' after processing is complete.
Response.BufferOutput = True
' Add the file name and attachment,
' which will force the open/cance/save dialog to show, to
the header
Response.AddHeader("Content-Disposition", "attachment;
filename=" + name)
' bypass the Open/Save/Cancel dialog
'Response.AddHeader("Content-Disposition", "inline;
filename=" + name)
' Add the file size into the response header
Response.AddHeader("Content-Length", Proc.Length.ToString())
' Set the ContentType
Response.ContentType = "application/octet-stream"
' Write the document into the response
While dataLengthToRead > 0 AndAlso
Response.IsClientConnected
Dim lengthRead As Int32 = ms.Read(buffer, 0, blockSize)
Response.OutputStream.Write(buffer, 0, lengthRead)
'Response.Flush(); // do not flush since BufferOutput =
true
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Flush()
Response.Close()
End Using
' End the response
'Response.End()
AckPanel.Visible = True
ReadPanel.Visible = False
Catch ex As Exception
End Try
End Sub