Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generate a html file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
hi everybody!!!!
Can you tell me why i can generate a html file with coldfusion???
using cffile for example

can you give me an example???
Thanks!!!!!!!!!
 

You can create a custom tag for this. If there are too many htm files that you need to create.

<!--- A file that calls the custom tag --->

<cfset FilePath = &quot;c:\temp\myoutputfile.htm&quot;>

<cfmodule name=&quot;static&quot; url=&quot;generateHtm.cfm&quot; destination=#FilePath#>


<!--- generateHtm.cfm is the file you need to generate into html file --->
You codes for that ....

<!--- Custom Tag, static.cfm --->

<CFIF Not IsDefined(&quot;Attributes.URL&quot;)>
Attribute URL is required. <BR>
<CFABORT>
</cfif>

<CFIF Not IsDefined(&quot;Attributes.Destination&quot;)>
Attribute Destination is required. <BR>
<CFABORT>
</cfif>

<cfhttp method=&quot;GET&quot; url=&quot;#Attributes.URL#&quot;></cfhttp>

<cffile action=&quot;WRITE&quot; file=&quot;#Attributes.Destination#&quot; output=&quot;#CFHTTP.FileContent#&quot;>

Above the code, htm file that is being genearted is myoutputfile.htm at c:\temp
This is just an example, you can change the path you want to store these files.

Good Luck

-sshhz-
 
Here is a very basic example:

<cffile action=&quot;write&quot; file=&quot;c:\inetpub\ output='
<html>
<title>My created html page</title>
<body>
It all goes here.... etc...
</body>
</html>

'>

Notice where the opening and closing output part of the tag is. Everything in that attribute will be written in the file.

If you are using CF 5, the cfsavecontent tag makes it a little easier to understand It will save everything you want in the file to a variable called HtmlOutput and the cffile line is easier to write:

<cfsavecontent variable=&quot;HtmlOutput&quot;>
<html>
<title>My Output page</title>
<body>Stuff goes here</body>
</html>
</cfsavecontent>

<cffile action=&quot;WRITE&quot; file=&quot;c:\inetpub\ output=&quot;#HtmlOutput#&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top