Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Rewrite simple JScript code to VB.NET

Posted on 2007-11-20
6
418 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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