SoFunction
Updated on 2025-04-14

ASP essence source code collection (five-year summary) page 7/20


ASP function to send emails using CDONTS
<%
'Last Updated By Recon On 05/14/2001
'On Error Resume Next
'Use CDONTS component to send emails on Win2k
'Send regular emails
SendMail "admin@", "iamchn@", "Normal Mail!", "Please check the attatchment!", 2, 0, "C:\"
'Send HTML mail
Dim m_fso, m_tf
Dim m_strHTML
Set m_fso = ("")
Set m_tf = m_fso.OpenTextFile("C:\", 1)
m_strHTML = m_tf.ReadAll
'Write m_strHTML
Set m_tf = Nothing
Set m_fso = Nothing
SendMail "admin@", "iamchn@", "HTML Mail!", m_strHTML, 2, 1, Null
'Parameter description
'strFrom : Sender Email
'strTo : Recipient Email
'strSubject : Letter subject
'strBody : Letter text
'lngImportance : The importance of letters
' : 0 - Low importance
' : 0 - Medium importance (default)
' : 0 - High importance
'lngAType : Letter format
': When it is 1, use the email body as HTML (HTML mail can be sent at this time)
'strAttach : The path to the attachment
Sub SendMail(strFrom, strTo, strSubject, strBody, lngImportance, lngAType, strAttach)
Dim objMail
Set objMail = ("")
With objMail
.From = strFrom
.To = strTo
.Subject = strSubject
.Body = strBody
.Importance = lngImportance
If lngAType = 1 Then
.BodyFormat = 0
.MailFormat = 0
End If
If IsEmpty(strAttach) = False And IsNull(strAttach) = False Then
.AttachFile strAttach
End If
.Send
End With
Set objMail = Nothing
End Sub
%>
Handle drives and folders
Using FileSystemObject (FSO) object mode, drives and folders can be processed in a planned manner, just like they are handled interactively in Windows Explorer. You can copy and move folders, get information about drives and folders, and more.
Get information about the drive
Drive objects can be used to obtain information about various drives that are physically connected to the system or over a network. Its properties can be used to obtain the following information:
Total capacity of the drive, in bytes (TotalSize property)
What is the available space for the drive, in bytes (AvailableSpace or FreeSpace attribute)
Which number is assigned to the drive (DriveLetter property)
What is the type of drive, such as removable, fixed, networked, CD-ROM or RAM disk (DriveType property)
The serial number of the drive (SerialNumber property)
The file system type used by the drive, such as FAT, FAT32, NTFS, etc. (FileSystem property)
Is the drive usable (IsReady property)
Share and/or volume name (ShareName and VolumeName properties)
The path or root folder of the drive (Path and RootFolder properties)
Please examine the sample code to understand how to use these properties in FileSystemObject.
Drive object usage example
Use Drive objects to collect information about the drive. In the following code, there is no reference to the actual Drive object; instead, use the GetDrive method to get a reference to the existing Drive object (in this example, drv).
The following example shows how to use a Drive object in VBScript:
Sub ShowDriveInfo(drvPath)
Dim fso, drv, s
Set fso = CreateObject("")
Set drv = ((drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & & "<br/>"
s = s & "Total Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br/>"
s = s & "Free Space: " & FormatNumber( / 1024, 0)
s = s & " Kb" & "<br/>"
s
End Sub
The following code shows the same functionality in JScript:
function ShowDriveInfo1(drvPath)
{
var fso, drv, s ="";
fso = new ActiveXObject("");
drv = ((drvPath));
s += "Drive " + ()+ " - ";
s += + "<br/>";
s += "Total Space: " + / 1024;
s += " Kb" + "<br/>";
s += "Free Space: " + / 1024;
s += " Kb" + "<br/>";
(s);
}
Process folders
In the following table, ordinary folder tasks and methods of executing them are described.
Task Method
Create a folder.
Delete the folder. or
Move folders. or
Copy the folder. or
Search the name of the folder.
If the folder exists on the drive, find it.
Gets an instance of an existing Folder object.
Find the parent folder name of the folder.
Find the path to the system folder.
Please check the sample code to see how many methods and properties are used in FileSystemObject.
The following example shows how to use Folder and FileSystemObject objects in VBScript to manipulate folders and obtain information about them:
Sub ShowFolderInfo()
Dim fso, fldr, s
' Get an instance of FileSystemObject.
Set fso = CreateObject("")
' Get the Drive object.
Set fldr = ("c:")
' Print the parent folder name.
"Parent folder name is: " & fldr & "<br/>"
' Print the driver name.
"Contained on drive " & & "<br/>"
' Print the root file name.
If = True Then
"This is the root folder." & ""<br/>"<br/>"
Else
"This folder isn't a root folder." & "<br/><br/>"
End If
' Create a new folder with the FileSystemObject object.
("C:\Bogus")
"Created folder C:\Bogus" & "<br/>"
' Print the basic name of the folder.
"Basename = " & ("c:\bogus") & "<br/>"
' Delete the newly created folder.
("C:\Bogus")
"Deleted folder C:\Bogus" & "<br/>"
End Sub
The following example shows how to use Folder and FileSystemObject objects in JScript:
function ShowFolderInfo()
{
var fso, fldr, s = "";
// Get an instance of FileSystemObject.
fso = new ActiveXObject("");
// Get the Drive object.
fldr = ("c:");
// Print the parent folder name.
("Parent folder name is: " + fldr + "<br/>");
// Print the drive name.
("Contained on drive " + + "<br/>");
// Print the root file name.
if ()
("This is the root folder.");
else
("This folder isn't a root folder.");
("<br/><br/>");
// Create a new folder with the FileSystemObject object.
("C:\\Bogus");
("Created folder C:\\Bogus" + "<br/>");
// Print the basic name of the folder.
("Basename = " + ("c:\\bogus") + "<br/>");
// Delete the newly created folder.
("C:\\Bogus");
("Deleted folder C:\\Bogus" + "<br/>");
}
ASP paging function
Function ExportPageInfo(ByRef rs,curpage,i,LinkFile)
Dim retval, j, pageNumber, BasePage
retval = "Thread" & curpage & "Page/Total" & & "Page"
retval = retval & "This page" & i & "Post/Total" & & "Post"
If curpage = 1 Then
retval = retval & "Home Page Previous Page"
Else
retval = retval & "<a href='" & LinkFile & "page=1'>Home</a> <a href='" & LinkFile & "page=" & cstr(curpage - 1) & "'>Previous Page</a> "
End If
If curpage = Then
retval = retval & "Last page Last page"
Else
retval = retval & "<a href='" & LinkFile & "page=" & cstr(curpage + 1) & "'>Last Page</a> <a href='" & LinkFile & "page=" & cstr() & "'>Last Page</a>"
End if
retval = retval & "<br/>"
BasePage = (curpage \ 10) * 10
If BasePage > 0 Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage - 9) & "'><<</a>"
For j = 1 to 10
pageNumber = BasePage + j
If PageNumber > Then Exit For
If pageNumber = Cint(curpage) Then
retval = retval & " <font color='#FF0000'>" & pageNumber & "</font>"
Else
retval = retval & " <a href='" & LinkFile & "page=" & pageNumber & "'>" & pageNumber & "</a>"
End If
Next
If > BasePage Then retval = retval & " <a href='" & LinkFile & "page=" & (BasePage + 11) & "'>>></a>"
ExportPageInfo = retval
End Function
application
<%
"SELECT * FROM news ORDER BY addtime DESC", conn, 1, 1
if <> 0 then
"Database operation failed:"&
else
if and then
"No record"
else
%>
<div align="center">
<center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr class="big">
<td width="60%">News Title</td>
<td width="25%" align="center">Date</td>
<td width="15%" align="center">Operation</td>
</tr>
<%
= 10
= curpage
for i = 0 to 9
%>
<tr>
<td><%= adoPageRS("title") %></td>
<td align="center">
<% = adoPageRS("addtime") %>
</td>
<td align="center"><a href=../../'?action=edit&id=<%= adoPageRS("id")%>'>Edit</a>
<a href='javascript:confirmDel(<%= adoPageRS("id") %>)'>Delete</a></td>
</tr>
<%

if then
i = i + 1
exit for
End If
next
%>
<tr align="center">
<td colspan="3">
<% = ExportPageInfo(adoPageRS, curpage, i, "?") %>
</td>
</tr>
</table>
</center>
</div>
Previous page1234567891011121314151617181920Next pageRead the full text