Posted At : July 15, 2008 1:15 PM | Posted By : Admin
Related Categories:
cfexchange
This is an Example showing the usage of cfexchange tags.This example shows how to connect and get messages from the server.
Note: You need to update the Application.cfm file with the appropriate values for exchange server, user ids, password, email ids.
<cftry> <!--- Send an email, to verify ---> <cfmail to = "#email1#"
from = "#email2#"
subject = "Testing cfexchange message 1"
username = "#user1#"
password = "#password#"
server = "#exchangeServerIP#"
port = "25">
This message is sent by cfexchange test. </cfmail>
<!--- Sleep for sometime so that the message is transferred/sent to the server. ----> <cfscript>sleep(15000);</cfscript>
<!--- Connect to the server using cfexchangeconnection. ----> <cfexchangeConnection
action="open"
username ="#user1#"
password="#password#"
server="#exchangeServerIP#"
connection="testconn1">
<!--- Get the mails from the server using cfexchangemail. ----> <cfexchangeMail action="get" connection="testconn1" name="getMessages"> <cfExchangeFilter name="subject" value="message 1"> </cfexchangeMail>
<cfdump var="#getMessages#">
<!--- Close the connection. ----> <cfexchangeConnection
action="close"
connection="testconn1"> <cfcatch> <cfoutput>#CFCATCH.message#</cfoutput> </cfcatch> </cftry>
You can download the source files using the download button.
Posted At : May 22, 2008 8:28 AM | Posted By : Admin
Related Categories:
Functions
Following is an example to show the usage of the function "URLEncodedFormat".
Description: Generates an URL-encoded string. For example, it replaces spaces with %20,
and non-alphanumeric characters with equivalent hexadecimal escape sequences.
Returns: A copy of a string, URL-encoded.
syntax: URLEncodedFormat(string [, charset ])
string: A string or a variable that contains a string.
charset: The character encoding in which the string is encoded. Optional.
<cfset enc = URLEncodedFormat("Adobe Cold Fusion 8")> <br><cfoutput>The URLEncodedFormat of "Adobe Cold Fusion 8" is <br>"#enc#". </cfoutput>
<br><cfset enc = URLEncodedFormat("JRUN&ColdFusion 8.0.1")> <cfoutput>The URLEncodedFormat of "JRUN&ColdFusion 8.0.1" is <br>"#enc#". </cfoutput>
Another example follows:
<h3>URLEncodedFormat Example</h3> <cfif IsDefined("url.myExample")> <p>The url variable url.myExample was passed from the previous link ...
its value is: <br><b>"<cfoutput>#url.myExample#</cfoutput>"</b> </cfif> <p>This function returns a URL encoded string. <cfset s = "My url-encoded string has special characters & other stuff"> <p><A HREF = "urlencodedformat.cfm?myExample=<cfoutput>#URLEncodedFormat(s)# </cfoutput>">Click me</A>
You can download the code using the download button.
Posted At : May 20, 2008 9:14 AM | Posted By : Admin
Related Categories:
cfchart
Example to show the usage of cfchart embedded inside cfdocument.
Description:
Embed a cfchart inside a cfdocument.
Note: In case of cfcharts, if you want to embed a cfchart inside a cfdocument, you can use the following formats for cfchart.
1. jpg 2. png
Currently, format="flash" is NOT supported.
You should have the datasource cfdocexamples(this comes by default with the installation)
<!---The following example analyzes the salary data in the cfdocexamples
database and generates a bar chart showing average salary by department. The
body of the cfchartseries tag includes one cfchartdata tag to include data that
is not available from the query. --->
<cfdocument format="pdf">
<!--- Get the raw data from the database. ---> <cfquery name="GetSalaries" datasource="cfdocexamples">
SELECT Departmt.Dept_Name,
Employee.Dept_ID,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID = Employee.Dept_ID </cfquery>
<!--- Use a query of queries to generate a new query with statistical data for each department.
AVG and SUM calculate statistics. GROUP BY generates results for each department. ---> <cfquery dbtype="query" name="DataTable">
SELECT
Dept_Name,
AVG(Salary) AS avgSal,
SUM(Salary) AS sumSal
FROM GetSalaries
GROUP BY Dept_Name </cfquery>
<!--- Reformat the generated numbers to show only thousands. ---> <cfloop index = "i" from = "1" to = "#DataTable.RecordCount#"> <cfset DataTable.sumSal[i] = Round(DataTable.sumSal[i]/1000)*1000> <cfset DataTable.avgSal[i] = Round(DataTable.avgSal[i]/1000)*1000> </cfloop>
<h1>Employee Salary Analysis</h1> <!--- Bar graph, from Query of Queries ---> <cfchart format="jpg" xaxistitle="Department" yaxistitle="Salary Average"> <cfchartseries type="cone" query="DataTable" itemcolumn="Dept_Name" valuecolumn="avgSal"> <cfchartdata item="Facilities" value="35000"> </cfchartseries> </cfchart>
</cfdocument>
You can download the example code using the download link.
Note: You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.
<!--- List all files in the current directory based on the following filters:
Get files whose filenames have only FOUR characters followed by the 'cfm' extension type. ex:test.cfm, fun1.cfm etc
---> <cfset filters = "????.cfm">
<!--- Output file list. ---> <cfdump var="#dirlist#" label="Files with four chars"> <br>
<!--- Multiple filters:
Get files whose filenames have only FOUR characters followed by the 'cfm' extension type. ex:test.cfm, fun1.cfm etc
And
Get files whose filenames have only THREE characters followed by the 'cfm' extension type. ex:fun.cfm
And
Get ALL files with .cfc extension. ex:app.cfc
---> <cfset filters = "????.cfm|???.cfm|*.cfc"> <cfdirectory
action="list"
directory="#ExpandPath( '.' )#"
filter="#filters#"
listinfo="name"
name="dirlist"
/>
Note: You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.
<!--- List all files in the current directory based on the following filters(single filter). ---> <cfset filters = "*.cfm">
Posted At : May 12, 2008 12:30 PM | Posted By : Admin
Related Categories:
cfftp
Here is an Example to show the usage of cfftp.
cfftp lets users implement File Transfer Protocol operations. By default, cfftp caches
an open connection to an FTP server. cfftp operations are usually of two types:
1. Establishing a connection
2. Performing file and directory operations
This example opens and verifies a connection, lists the files in a directory, and closes
the connection.
<!--- Open a connection ---> <cfftp action = "open"
username = "user1"
connection = "myconn"
password = "mypwd"
server = "10.192.36.229"
stopOnError = "Yes">
<!--- Did the connection succeed... ---> <cfoutput>#cfftp.succeeded#</cfoutput>
<!--- List the files in a directory... ---> <cfftp action = "LISTDIR"
stopOnError = "Yes"
name = "ListFiles"
directory = "/"
connection = "myconn">
<!--- Display the contents of the array ---> <p>
Your array contents are: <cfdump var="#MyArray#"> </p>
<cfoutput> <!--- Check if the elements are defined. ---> <p>Does element 1 exist?
#ArrayIsDefined(MyArray, 1)# <p>Does element 2 exist?
#ArrayIsDefined(MyArray, 2)# <p>Does element 3 exist?:
#ArrayIsDefined(MyArray, 3)#</p> </cfoutput>
Note: This function currently throws an error if the array is NOT initialized.
So if the array is not yet created, you should surround the ArrayIsDefined code in a block.
Also, the ArrayIsDefined function throws an error if you test for an element beyond the length of the array.
To prevent this error, you can surround the test in the ArrayLen function.
You can download the cfm code using the download button.