コード例 #1
0
        /// <summary>
        /// Managed version of GetPrivateProfileString<br/>
        /// No COM Interop is used<br/>
        /// If the file does not exist or the value is not in the file, the defaultValue is used.<br/>
        /// See:  http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
        /// </summary>
        /// <param name="sectionName">The INI Section Name. Use GLOBAL for the global section.</param>
        /// <param name="settingName">The INI Setting Name</param>
        /// <param name="defaultValue">The default value if there is no value</param>
        /// <param name="returnedString">Output of the string</param>
        /// <param name="size">The number of buffer characters (not used but here for backward compatibility)</param>
        /// <param name="filePath">The path to the INI file</param>
        /// <returns>Number of characters returned</returns>
        /// <exception caption="" cref="ArgumentNullException">Occurs when sectionName, settingName or filePath is null</exception>
        public static int GetPrivateProfileString(string sectionName, string settingName, string defaultValue, out string returnedString, int size, string filePath)
        {
            IniReaderWriter iniReaderWriter = new IniReaderWriter();

            returnedString = iniReaderWriter.GetSetting(sectionName, settingName, filePath) ?? defaultValue;

            if (returnedString == null)
            {
                return(0);
            }

            return(returnedString.Length);
        }
コード例 #2
0
 /// <summary>
 /// Read Data from an INI File
 /// </summary>
 /// <param name="section">Section Name</param>
 /// <param name="key">Key Name</param>
 /// <returns>Value</returns>
 public string IniReadValue(string section, string key)
 {
     try
     {
         StringBuilder temp = new StringBuilder(255);
         IniReaderWriter.GetPrivateProfileString(section, key, string.Empty, temp, 255, Path);
         return(temp.ToString());
     }
     catch
     {
         return(string.Empty);
     }
 }
コード例 #3
0
        /// <summary>
        /// Managed version of GetPrivateProfileString<br/>
        /// No COM Interop is used<br/>
        /// If the file does not exist or the value is not in the file, the defaultValue is used.<br/>
        /// See:  http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
        /// </summary>
        /// <param name="sectionName">The INI Section Name.  Use GLOBAL for the global section.</param>
        /// <param name="settingName">The INI Setting Name</param>
        /// <param name="defaultValue">The default value if there is no value</param>
        /// <param name="returnedBuffer">StrinbBuilder Output of the string</param>
        /// <param name="size">The number of buffer characters (not used but here for backward compatibility)</param>
        /// <param name="filePath">The path to the INI file</param>
        /// <returns>Number of characters returned</returns>
        /// <exception cref="ArgumentNullException">Occurs when sectionName, settingName or filePath is null</exception>
        public static int GetPrivateProfileString(string sectionName, string settingName, string defaultValue, StringBuilder returnedBuffer, int size, string filePath)
        {
            IniReaderWriter iniReaderWriter = new IniReaderWriter();

            string result = iniReaderWriter.GetSetting(sectionName, settingName, filePath) ?? defaultValue;

            if (result == null)
            {
                return(0);
            }

            returnedBuffer.Append(result);
            return(result.Length);
        }
コード例 #4
0
        /// <summary>
        /// Managed version of GetPrivateProfileInt<br/>
        /// No COM Interop is used<br/>
        /// If the file does not exist or the value is not in the file, the defaultValue is used.<br/>
        /// See:  http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
        /// </summary>
        /// <param name="sectionName">The INI Section Name. Use GLOBAL for the global section.</param>
        /// <param name="settingName">The INI Setting Name</param>
        /// <param name="defaultValue">The default value if there is no value</param>
        /// <param name="filePath">The path to the INI file</param>
        /// <returns>The integer</returns>
        /// <exception caption="" cref="ArgumentNullException">Occurs when sectionName, settingName or filePath is null</exception>
        public static int GetPrivateProfileInt(string sectionName, string settingName, int defaultValue, string filePath)
        {
            int             result          = defaultValue;
            IniReaderWriter iniReaderWriter = new IniReaderWriter();

            string value = iniReaderWriter.GetSetting(sectionName, settingName, filePath);

            if (String.IsNullOrEmpty(value))
            {
                return(result);
            }

            Int32.TryParse(value, out result);
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <param name="section">Section Name</param>
        /// <param name="key">Key Name</param>
        /// <param name="value">Value Name</param>
        public bool IniWriteValue(string section, string key, string value)
        {
            try
            {
                CheckINIPath();

                if (_iniPathWritable == false)
                {
                    return(false);
                }

                IniReaderWriter.WritePrivateProfileString(section, key, value, Path);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Managed version of WritePrivateProfileString<br/>
        /// No COM Interop is used<br/>
        /// If the file does not exist it will be created.  If the section does not exist it will be created.  If the setting already exists it will be updated.  If the setting does not exist, it will be added.<br/>
        /// See:  http://msdn.microsoft.com/en-us/library/windows/desktop/ms724348%28v=vs.85%29.aspx
        /// </summary>
        /// <param name="sectionName">The INI Section Name. Use GLOBAL for the global section.</param>
        /// <param name="settingName">The INI Setting Name</param>
        /// <param name="settingValue">The INI Setting Value</param>
        /// <param name="filePath">The path to the INI file</param>
        /// <exception cref="ArgumentNullException">Occurs when sectionName, settingName or filePath is null</exception>
        /// <returns>True if the setting was set successfully</returns>
        /// <exception caption="" cref="ArgumentNullException">Occurs when sectionName, settingName or filePath is null</exception>
        public static bool WritePrivateProfileString(string sectionName, string settingName, string settingValue, string filePath)
        {
            IniReaderWriter iniReaderWriter = new IniReaderWriter();

            return(iniReaderWriter.SaveSetting(sectionName, settingName, settingValue, filePath));
        }