Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Rewrite simple JScript code to VB.NET

Posted on 2007-11-20
6
Medium Priority
?
431 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 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

971 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