Config Helper
GetPrivateProfileString(String,String,String,String,Int32,String) Method
Example 



KellermanSoftware.ConfigHelper Namespace > IniReaderWriter Class > GetPrivateProfileString Method : GetPrivateProfileString(String,String,String,String,Int32,String) Method
The INI Section Name. Use GLOBAL for the global section.
The INI Setting Name
The default value if there is no value
Output of the string
The number of buffer characters (not used but here for backward compatibility)
The path to the INI file
Managed version of GetPrivateProfileString
No COM Interop is used
If the file does not exist or the value is not in the file, the defaultValue is used.
See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
Syntax
Public Overloads Shared Function GetPrivateProfileString( _
   ByVal sectionName As String, _
   ByVal settingName As String, _
   ByVal defaultValue As String, _
   ByRef returnedString As String, _
   ByVal size As Integer, _
   ByVal filePath As String _
) As Integer
Dim sectionName As String
Dim settingName As String
Dim defaultValue As String
Dim returnedString As String
Dim size As Integer
Dim filePath As String
Dim value As Integer
 
value = IniReaderWriter.GetPrivateProfileString(sectionName, settingName, defaultValue, returnedString, size, filePath)
public static int GetPrivateProfileString( 
   string sectionName,
   string settingName,
   string defaultValue,
   out string returnedString,
   int size,
   string filePath
)
public:
static int GetPrivateProfileString( 
   String^ sectionName,
   String^ settingName,
   String^ defaultValue,
   [Out] String^ returnedString,
   int size,
   String^ filePath
) 

Parameters

sectionName
The INI Section Name. Use GLOBAL for the global section.
settingName
The INI Setting Name
defaultValue
The default value if there is no value
returnedString
Output of the string
size
The number of buffer characters (not used but here for backward compatibility)
filePath
The path to the INI file

Return Value

Number of characters returned
Exceptions
ExceptionDescription
Occurs when sectionName, settingName or filePath is null
Example
string expectedValue = "This is a test";
IniReaderWriter.WritePrivateProfileString("MySection", "MySettingName", expectedValue, "MySettingsFile.ini");
 
string actualValue;
 
int numberOfCharactersReturned = IniReaderWriter.GetPrivateProfileString("MySection", "MySettingName", string.Empty, out actualValue, 255, "MySettingsFile.ini");
Console.WriteLine(actualValue);
Dim expectedValue As String = "This is a test"
IniReaderWriter.WritePrivateProfileString("MySection", "MySettingName", expectedValue, "MySettingsFile.ini")
 
Dim actualValue As String
 
Dim numberOfCharactersReturned As Integer = IniReaderWriter.GetPrivateProfileString("MySection", "MySettingName", String.Empty, actualValue, 255, "MySettingsFile.ini")
Console.WriteLine(actualValue)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IniReaderWriter Class
IniReaderWriter Members
Overload List