Solved

Rewrite simple JScript code to VB.NET

Posted on 2007-11-20
6
415 Views
Last Modified: 2011-10-03
Can someone please re-write for me this simple JScript code to VB.NET.
The code is basically generate a PDF file and display it in client's web browser.

Thanks

<%@ LANGUAGE=JScript %>
<%
//create the pdf
shl = Server.CreateObject("WScript.Shell")
argument = "\"c:\\omniformat\\html2pdf995.exe\" "
//argument = argument + "\"c:\\pdf995\\readme.html\" "
argument = argument + "\"www.epad995.com\" "
argument = argument + "\"c:\\inetpub\\wwwroot\\out.pdf\""
//run html2pdf995 and wait for it to return
shl .Run(argument, 0 , 1 )

//display the pdf
Response.ClearContent
Response.ContentType = "application/pdf"
Response.Redirect ("http://localhost/out.pdf")
%>

0
Comment
Question by:Terrace
  • 3
  • 3
6 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20325965
In .NET you use the Process and ProcessStartInfo classes to run a program.

Clearing the content and setting the content type before calling Response.Redirect has no effect at all. That's what you do if you send the data back in the same response using Response.BinaryWrite or Response.WriteFile.
Dim program As String = "c:\omniformat\html2pdf995.exe"

Dim argument As String = """c:\pdf995\readme.html"" ""www.epad995.com"" ""c:\inetpub\wwwroot\out.pdf"""
 

Dim process As New System.Diagnostics.Process

process.StartInfo = New System.Diagnostics.ProcessStartInfo(program, argument)

process.Start()

process.WaitForExit()
 

Response.Redirect("http://localhost/out.pdf")

Open in new window

0
 

Author Comment

by:Terrace
ID: 20328666
Thank you very much.
I played with this code and made some modifications to accomodate paths and other stuff.
This is all new to me, but hopefully will make it work.
As a test, I created a button on my web form and inserted your code such as

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim program As String = "c:\ProgramFiles\omniformat\html2pdf995.exe"
        Dim argument As String = """c:\ProgramFiles\pdf995\readme.html"" ""c:\TestWebLock\PDF\30222.pdf"" ""c:\TestWebLock\PDF\out.pdf"""
        Dim process As New System.Diagnostics.Process
        process.StartInfo = New System.Diagnostics.ProcessStartInfo(program, argument)
        process.Start()
        process.WaitForExit()
       Response.Redirect("http://192.24.251.26:8081/PDF/out.pdf")
    End Sub

When I click on the button, I expect to have the out.pdf file displayed in browser window.

I know this is out of scope of this question, but maybe you have some idea or can help me troubleshoot it.

P.S. you already deserved the points, so this is just your good will.

Thanks. Happy Thanksgiving
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20331672
Perhaps I can help you troubleshoot it if you tell me what the trouble is...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20452826
Checking back... you never answered what the the trouble was?
0
 

Author Comment

by:Terrace
ID: 20495205
I got too busy with this project.
Your code helped me to get started, so I thank you for that.
0
 

Author Comment

by:Terrace
ID: 20495220
This is how this code looks like in VB.NET
Dim program As String = "C:\Program Files\omniformat\omniformat.exe"
 

Dim argument As String = Chr(34) & "C:\TestWebLock\Rates\" + strTransID & Chr(34) & " " & Chr(34) & "PDF" & Chr(34)
 

Dim process As New System.Diagnostics.Process

process.StartInfo = New System.Diagnostics.ProcessStartInfo(program, argument)

process.Start()

process.WaitForExit()

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now