Solved

How to output an html file using VB script

Posted on 2008-06-18
7
706 Views
Last Modified: 2011-10-03
Greetings,

I have a routine that parses a record set and creates an xml file for each record - see the code below.  Now I need to create an html file that contains links to each of the files that were generated.  How would I include this html file as output so that xml file links appear in the html file?

Notice the line below that reads:

' ******* modify xml file name so that it is written as a link *********

I'm assuming this is the only thing that keeps me from doing what I need.  I can't figure out what is necessary in terms of a file path and/or the link syntax

Thanks!

Set Records = SqlCmd.Execute 

     

	    If Records.EOF Then 

	        MsgBox "No Records returned."

		    strResults = ""

	    Else

  	        Set objFSO1 = CreateObject("Scripting.FileSystemObject")

   	        Set objFSO2 = CreateObject("Scripting.FileSystemObject")

            Set objNewFile1 = objFSO1.CreateTextFile("C:\XmlIndex.html", ForAppending)  ' ********  html file *********

 

            Do Until Records.EOF

              strLine = ""

	            For DataFields = 0 To Records.Fields.Count -1.

		            If DataFields = 0 Then		              

			            

   			    	strNewFile2 = Records.Fields(DataFields).Value & ".xml"        ' ********  xml file name ********

			        strLine = Records.Fields(DataFields).Value

			            

                        	Set objNewFile2 = objFSO2.CreateTextFile("C:\" & strNewFile2, ForWriting)

 

                        	strNewFile2 =   ' ******* modify xml file name so that it is written as a link *********

   			        objNewFile1.WriteLine strNewFile2   ' ********  write to html file using xml file name *********

		            Else

			        strLine = strLine & "," & Records.Fields(DataFields).Value

	                    	objNewFile2.WriteLine strLine

	                    	objNewFile2.Close

		            End If

	            Next        	

	            Records.MoveNext

 

            Loop

            objNewFile1.Close

            Set objFSO1 = Nothing

            Set objFSO2 = Nothing

            Set objNewFile1 = Nothing

            Set objNewFile2 = Nothing

Open in new window

0
Comment
Question by:John500
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Dxpert
Comment Utility
Are you running this on a intranet?
This code will only work on IE and on the same PC where the XML files are.


If DataFields = 0 Then                            
  strNewFile2 = Records.Fields(DataFields).Value & ".xml"        ' ********  xml file name ********
  strLine = Records.Fields(DataFields).Value
  strNewFileFullPath = "C:\" & strNewFile2  '** NEW LINE

  Set objNewFile2 = objFSO2.CreateTextFile(strNewFileFullPath, ForWriting) '** CHANGED LINE
  objNewFile1.WriteLine "<a href='" &  strNewFileFullPath & "'>" & strNewFile2 & "</a>"  '** CHANGED LINE
Else
...

0
 

Author Comment

by:John500
Comment Utility
Yes - running on an Intranet

Can I throw one more element in there which includes a simple title for the page along with the date it was written?

Thanks!

0
 
LVL 10

Expert Comment

by:Dxpert
Comment Utility
Not sure I know what you mean. Where do you want to add a Title and Date? To the body of HTML file, or to the LINK?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Accepted Solution

by:
Dxpert earned 500 total points
Comment Utility
Not sure which one you wanted, so I've added both:



Set objNewFile1 = objFSO1.CreateTextFile("C:\XmlIndex.html", ForAppending)  ' ********  html file *********

objNewFile2.WriteLine "<H1>XML File Title</H1>" '** ADDED LINE
 

Do Until Records.EOF

  strLine = ""

		  For DataFields = 0 To Records.Fields.Count -1.

					If DataFields = 0 Then                            

					  strNewFile2 = Records.Fields(DataFields).Value & ".xml"        ' ********  xml file name ********

					  strLine = Records.Fields(DataFields).Value

					  strNewFileFullPath = "C:\" & strNewFile2 '** ADDED LINE

					  strLinkTitle = "XML File Title - " & cstr(date()) '** ADDED LINE
 

					  Set objNewFile2 = objFSO2.CreateTextFile(strNewFileFullPath, ForWriting)

					  objNewFile1.WriteLine "<a href='" &  strNewFileFullPath & "'>" & strLinkTitle & "</a><br />" '** CHANGED LINE

					Else

						  strLine = strLine & "," & Records.Fields(DataFields).Value

						  objNewFile2.WriteLine strLine

						  objNewFile2.Close

					 End If

		  Next                

		  Records.MoveNext
 

Loop

Open in new window

0
 

Author Comment

by:John500
Comment Utility
I needed the title for the html file.... but thanks for the extra!!
0
 

Author Closing Comment

by:John500
Comment Utility
Thanks again
0
 
LVL 10

Expert Comment

by:Dxpert
Comment Utility
Thanks! Glad I could help ;-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

19 Experts available now in Live!

Get 1:1 Help Now