Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Word Document

Status
Not open for further replies.

LucasH

IS-IT--Management
Oct 28, 2003
93
US
Hi guys,

This is driving me nuts. I am relatively new to .NET and am using Visual Studio 2003. All I want to do is display a word document in the browser (I have a Crystal Reports application that exports to .doc and I want to display the results). After the Crystal Report is exported, the user is re-directed to a new webform, DOC.aspx, where in page_load I have the following code:

Dim myfile As String
myfile = "c:\inetpub\ & Session.SessionID.ToString & ".doc"
Response.ClearContent()
Response.ClearHeaders()
Response.Buffer = True
Response.ContentType = "application/ms-word"
Response.AddHeader("Content-Disposition", "attachment; filename=" & myfile)
Response.WriteFile(myfile)
Response.Flush()
Response.Close()
System.IO.File.Delete(myfile)

Upon execution, it prompts for Save/Open, if I choose Open, I get my list of applications from which to Open a file called DOC[1]. Why won't it just open my file to word and why is it seeing DOC[1] and not myfile? Any help on this seemingly basic issue would be appreciated.
 
post your crystal code. you must create the report first in crystal then export it. below is a sample for pdf. it should work for word as well you just need to modify the code.

Public Sub ExportData(ByRef oRpt As Object)
Dim fs As IO.FileStream
Dim FileSize As Long
Dim oDest As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim ExportFileName As String = Server.MapPath("/") & ConfigurationSettings.AppSettings("ExportDir") & Session.SessionID & ".pdf"

Try
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
oDest.DiskFileName = ExportFileName
oRpt.ExportOptions.DestinationOptions = oDest
oRpt.Export()
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Type", "application/pdf")
Response.AddHeader("Content-Disposition", "attachment;filename=" & Session.SessionID & ".pdf;")
fs = New IO.FileStream(ExportFileName, IO.FileMode.Open)
FileSize = fs.Length
Dim bBuffer(CInt(FileSize)) As Byte
fs.Read(bBuffer, 0, CInt(FileSize))
fs.Close()
Response.BinaryWrite(bBuffer)
Response.Flush()
Response.Close()
Catch e As Exception
End Try

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top