Create and Display Doc

I have a web app which creates a report on the fly. I would like it to them open and display what I’ve created immediately.

When running on a webserver, I cannot save to C, so what method do I use. Do I NEED to save it first? The following works when I run it locally…

Dim sSQLText As String
sSQLText = "SELECT TheYear ETC"

Using connection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("VisionExtendDevelopmentCS").ConnectionString)
Dim cmd As New SqlCommand()
cmd.Connection = connection
cmd.Connection.Open()
cmd.CommandText = sSQLText

Dim dr As SqlDataReader = cmd.ExecuteReader

Dim license As New Aspose.Words.License
license.SetLicense("Aspose.Total.lic")
Dim doc As Aspose.Words.Document = New Aspose.Words.Document()
Dim builder As New DocumentBuilder(doc)

Dim rowFormat As Tables.RowFormat = builder.RowFormat

Dim font As Aspose.Words.Font = builder.Font
font.Name = "Calibri"
font.Size = "11"
font.Bold = True

builder.StartTable()
builder.InsertCell()
builder.Write("Proposal Results Tracking")
builder.EndRow()

rowFormat.ClearFormatting()

font.Name = "Calibri"
font.Size = "11"
font.Bold = False

builder.InsertCell()
builder.Write("The following data summarizes the " & iSelectedYear & " year to date proposal results:")
builder.EndRow()

While dr.Read
builder.InsertCell()
builder.Write(dr.Item("PropCount") & " Proposals / Qualifications have been initiated")
builder.EndRow()
'ETC
End While

builder.EndTable()

For iSectCount = 0 To doc.Sections.Count - 1
doc.Sections(iSectCount).PageSetup.BottomMargin = "21.6"
doc.Sections(iSectCount).PageSetup.TopMargin = "21.6"
doc.Sections(iSectCount).PageSetup.LeftMargin = "21.6"
doc.Sections(iSectCount).PageSetup.RightMargin = "21.6"
doc.Sections(iSectCount).PageSetup.Orientation = Aspose.Words.Orientation.Landscape
doc.Sections(iSectCount).PageSetup.PaperSize = Aspose.Words.PaperSize.Letter
Next

Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)

’ Clear the borders all cells in the table.
table.ClearBorders()

Dim pdfSaveOptions As Aspose.Words.Saving.PdfSaveOptions = New Aspose.Words.Saving.PdfSaveOptions()
Dim sFilename As String

sFilename = "c:\Proposal Results YTD - " & Format(Now, "yyyy-MM-dd-h-mm-ss") & ".pdf"
doc.Save(sFilename, pdfSaveOptions)
System.Diagnostics.Process.Start(sFilename)

Hi Rick,

Thanks
for your inquiry. I would suggest you please read the following article
that outlines ‘how to send a document to client’s browser’:
https://docs.aspose.com/words/net/save-a-document/

Please let me know if I can be of any further assistance.

I’ve seen that article but it seems like it is loading an existing document. I am creating a document on the fly which I want to open.

but let’s assume it doesn’t matter. I do have a “doc” already set up, so if I just add this line…

doc.Save(Response, "Report Out.doc", ContentDisposition.Inline, Nothing)

…it causes an error “Overload resolution failed because no accessible ‘Save’ accepts this number of arguments.”

For reference, my Doc delcaration is:

Dim doc As Aspose.Words.Document = New Aspose.Words.Document()

I’ll see how I can go abut changing which DLL I use, but I’m unsure of how to do that.

’ If this method overload is causing a compiler error then you are using the Client Profile DLL whereas
’ the Aspose.Words .NET 2.0 DLL must be used instead.

How do I use the other DLL?
Is is referring to Aspose.Words.dll?

What are the advantages of using 3.5? In other words, am I going to lose something if I go to 2.0?

I have gotten this to work, BUT, it opens in the same tab. I have researched trying to make it open in a new tab, but have not found anything yet.

Basically, after my BUILDER had finished with the doc, I run this code:

Dim stream As New MemoryStream()
doc.Save(stream, SaveFormat.Pdf)

Response.Expires = 0 
Response.Buffer = True 

Response.ClearContent()
'Specify the document type.

Response.ContentType = "application/pdf"

'Specify how the document is sent to the browser.
Response.AddHeader("content-disposition", "inline; filename=""YTD.pdf""")

Response.BinaryWrite(stream.ToArray()) 

'Get data bytes from the stream and send it to the response.
Dim bytes As Byte() = stream.GetBuffer()
Response.BinaryWrite(bytes)
Response.Flush()
Response.End()

It still opens in the new tab tho.

Hi Rick,

Thanks for your inquiry.

*Elwood472:

I’ve seen that article but it seems like it is loading an existing document. I am creating a document on the fly which I want to open.*

The shared example load the the document from disk. You can create a blank Word document by using following code snippet.

// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

*Elwood472:

doc.Save(Response, “Report Out.doc”, ContentDisposition.Inline, Nothing)

…it causes an error “Overload resolution failed because no accessible ‘Save’ accepts this number of arguments.”*

Please note that Aspose.Words DLL from net2.0 folder is used for 2.0, 3.0, 3.5 and 4.0 .Net Frameworks. This
assembly cannot be used when targeting the .NET Framework 3.5 or 4.0
Client Profile as it depends on System.Web. In such an environment use
the library under net3.5_ClientProfile instead.

In your case, please use net2.0 assembly of Aspose.Words. Hopefully it will serve your purpose. Please read more about Document.Save methods from here:
https://reference.aspose.com/words/net/aspose.words/document/save/

*Elwood472:

How do I use the other DLL?
Is is referring to Aspose.Words.dll?
What are the advantages of using 3.5? In other words, am I going to lose something if I go to 2.0?*

The net3.5_ClientProfile folder contains assemblies to use with .NET Framework 3.5 or 4.0 Client Profile. Note that this assembly excludes the Save overload accepting an HttpResponse object. This is by design as the client profile excludes System.Web assembly.

*Elwood472:

I have gotten this to work, BUT, it opens in the same tab. I have researched trying to make it open in a new tab, but have not found anything yet.

Basically, after my BUILDER had finished with the doc, I run this code:

Dim stream As New MemoryStream()
doc.Save(stream, SaveFormat.Pdf)

It still opens in the new tab tho.*

It is nice to hear from you that your problem has been solved. Aspose.Words sends the output to client browser which is working fine at your end. Could you please share some more detail about your query related to browser’s tab? Please share which browser you are using.

I got this working. I essentially created a new page which opens in a new tab. That pages then creates the report.

Hi Rick,

Thanks for your feedback. It is nice to hear from you that you have solved your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.