Description

Sets the value of a profile entry in an initialization file.

Returns

An empty string, upon successful execution; otherwise, an error message.

History

ColdFusion 11: Added the encoding parameter.

Category

System functions

Function syntax

SetProfileString(iniPath, section, entry, value, encoding)

See also

GetProfileSectionsGetProfileString

Parameters

Parameter

Description

iniPath

Absolute path of initialization file

section

Section of the initialization file in which the entry is to be set

entry

Name of the entry to set

value

Value to which to set the entry

encoding Encoding of the initialization (ini) file. For instance "UTF-8"

Example

<h3>SetProfileString Example</h3>
This example uses SetProfileString to set the time-out value in an
initialization file. Enter the full path of your initialization
file, specify the time-out value, and submit the form.
<!--- This section checks whether the form was submitted. If so, this
section sets the initialization path and time-out value to the
path and time-out value specified in the form --->
<cfif Isdefined("Form.Submit")>

<cfset IniPath = FORM.iniPath>
<cfset Section = "boot loader">
<cfset MyTimeout = FORM.MyTimeout>
<cfset timeout = GetProfileString(IniPath, Section, "timeout")>

<cfif timeout Is Not MyTimeout>
<cfif MyTimeout Greater Than 0>
<hr size = "2" color = "#0000A0">
<p>Setting the time-out value to <cfoutput>#MyTimeout#</cfoutput>
</p>
<cfset code = SetProfileString(IniPath,
Section, "timeout", MyTimeout)>
<p>Value returned from SetProfileString:
<cfoutput>#code#</cfoutput></p>
<cfelse>
<hr size = "2" color = "red">
<p>The time-out value should be greater than zero in order to
provide time for user response.</p>
<hr size = "2" color = "red">
</cfif>
<cfelse>
<p>The time-out value in your initialization file is already
<cfoutput>#MyTimeout#</cfoutput>.</p>
</cfif>
<cfset timeout = GetProfileString(IniPath, Section, "timeout")>
<cfset default = GetProfileString(IniPath, Section, "default")>

<h4>Boot Loader</h4>
<p>The time-out is set to: <cfoutput>#timeout#</cfoutput>.</p>
<p>Default directory is: <cfoutput>#default#</cfoutput>.</p>

</cfif>

<form action = "setprofilestring.cfm">
<hr size = "2" color = "#0000A0">
<table cellspacing = "2" cellpadding = "2" border = "0">
<tr>
<td>Full Path of Init File</td>
<td><input type = "Text" name = "IniPath"
value = "C:\myboot.ini"></td>
</tr>
<tr>
<td>Time-out</td>
<td><input type = "Text" name = "MyTimeout" value = "30"></td>
</tr>
<tr>
<td><input type = "Submit" name = "Submit" value = "Submit"></td>
<td></td>
</tr>
</table>
</form>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy