Two problems with ASP please help

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
 
N

Nathan Sokalski

For your first problem, trying to display a Word document in a web browser
is not a good idea. Web browsers were not intended to display types other
than the standard Web types (html, xml, gif, jpeg, and a couple others).
There are also plugins and viewers that are so common that it is usually
safe to use those types (pdf, quicktime, shockwave, etc.). Although some
browsers have added extra features to allow you to view certain file types,
unless you have a link to a plugin or viewer that the user can install to
view the type, you should not use it on the web. It is usually ok, however,
to allow the user to download the file and open it locally using another
application. Microsoft offers a free viewer for Word documents (not for
browsers, but you can use it to view the document outside the browser), and
you could also convert the Word document into a pdf so that the user can
view it in the browser. Adobe has an online service that allows you to
convert documents into pdf files for a very small charge (some people do not
want to spend the money to buy the expensive Acrobat software).

As for your second question, I think we will need to see more code
(including the *.aspx file) in order to help you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top