About the news system that generates HTML files

Source: Internet
Author: User
Tags date format create directory end naming convention
Generate Html| News System
The general transmission of the ID value of the news system is more likely to be produced is not very complicated.
But the news that we see on Sina or other portal class website is not passed by ID, but an HTML or shtml file, is it hand-added? Of course not, in fact, this is used in the ASP FileSystemObject object method.
Then tell me how to implement this function.
First consider the file name format and file storage path.
The path can be assumed that:
stored in the path: If all the HTML file or all the shtml files are placed in the same directory, when the number of simultaneous access to the number of people will inevitably affect the normal operation of the server, so the sensible way is to add these files by the date of the classification.
Format of file name:
To avoid files with duplicate names, the general naming convention is the date + time + random number + suffix name of the day.
function Makefilename ()
FName = Now ()
fname = replace (fname, "-", "")
fname = replace (fname, "", "")
fname = replace (fname, ":", "")
fname = replace (fname, "PM", "")
fname = replace (fname, "AM", "")
fname = replace (fname, "a.m.", "")
fname = replace (fname, "PM", "")
Randomize
Rannum=int (90000*rnd) +10000 ' generates random numbers
fname = Fname&fannum
Makefilename=fname & ". sHTML"
End Function
This function generates the required file name and the suffix name of the generated file, the current suffix named. shtml, or you can change to HTML or ASP.
Just mentioned is the name of the file, now again for the file storage path!
As mentioned earlier, each file is categorized by the date of accession, so how do you determine the path? The same is generated with the FSO.
Use the folderexists aspect of the FSO to determine if a directory exists, and if there is no need to re-establish it, simply write the HTML to the directory (this is something). If the FolderExists method gets a value of false to indicate that the directory does not exist, it must be generated using the CreateFolder method.
Formpath=datepart ("yyyy", Now ()) & "_" &datepart ("M", Now ()) & "_" &datepart ("D", Now ()) ' Create directory name, The generated files will be stored here
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
If not objfso.folderexists (Server.MapPath (formpath)) Then ' if the directory does not exist
Objfso.createfolder (Server.MapPath (Formpath)) ' Create a folder
End If
Set objFSO = Nothing
The catalog is set up like this. Each FSO to generate a file to judge, but this does not know will affect efficiency, we can have any good ideas can talk about.
First look at a template:
<title>----[title]</title> under Lemon Tree
<body>
[News_title]
<br>
Author: [Author] Source: [Source] Date added: [Add_time]
<br>
[Content]
</body>

This is one of the simplest templates, which in the [] enclosed is what dongdong? That is the news title, content, author, etc. that is about to be replaced.
First, regardless of this template drift not beautiful, first write data table, in the back of the use of yo!
Here's what we'll talk about the core, how do I generate HTML?
Write the previous template to the data table, which gives the structure of the table, which is, of course, a simple
Template table
t_id ' ID value, automatic numbering
T_name ' template name
T_content ' template code
After writing the news in the editor, the process in the processing page is as follows:
1, get the value of each variable in the form
2, from the Template table to get the template code
3. Replace the [] enclosed in the template with the corresponding form value, such as [Autor] for the author name obtained in the form
4. FSO generates HTML file
5, write the news to the data table (why write?) For later editing)
' Here query template
strSQL = "SELECT * from Templet where t_name= '" "&templet_name&" "
Objrs.open strsql,conn,1,1
Content = objRS ("content")
Objrs.close
' Begin the substitution, where the title/strcontet are obtained from the form, and the preceding code is omitted
Content = Replace (content, "[title]", title)
Content = Replace (content, "[content]", strcontent)
Content = Replace (content, "[Source]", source)
Content = Replace (content, "[author]", author)
Content = replace (content, [Add_time], now ())

' Then write the news to the datasheet
strSQL = "INSERT INTO News---------------"
Conn.execute Strsql,intno ' executive
If Intno <> 0 Then ' if the execution result is not 0 to perform successfully, the write is started
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Formpath=datepart ("yyyy", Now ()) & "_" &datepart ("M", Now ()) & "_" &datepart ("D", Now ()) ' Create directory name, The generated files will be stored here
filename = Server.MapPath (formpath& "/" &makefilename)
If Objfso.folderexists (Server.MapPath (formpath)) Then ' if the directory exists
Set file = objFSO. CreateTextFile (formpath& "\" &fname)
File. WriteLine Content
File.close
Else
Objfso.createfolder (Server.MapPath (Formpath)) ' Create a folder
Set file = objFSO. CreateTextFile (formpath& "\" &fname)
File. WriteLine Content
File.close
End If
Set objFSO = Nothing
Else
Response.Write "Write Data Failed!"
Response.End
End If
Edit is nothing more than to call the news content from the datasheet, update after the FSO to write!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.