473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to read and write data to an INI file

29
I am currently developing a windows application. I have a form that saves data to an ini file.

I am currently having a trouble in writing and reading ini file.

First, if the form loaded, it will read the ini file with corresponding section. it works well. But when I save / write data (one of it's key is a path (filename of the image))to ini file, changes does not reflect. When I closes the form and load it again, the data will be read as what i have saved though the changes doesn't reflect in ini file.

But, if I'm going to save the data and the path (file name of the image) is not included, changes reflects to the ini file.

I don't understand why is it happening.

I really need help here.

Below are my codes.

Save data to ini:
Expand|Select|Wrap|Line Numbers
  1. private void Save()
  2.         {
  3.             try
  4.             {               
  5.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "IMAGEPATH", imageFileName, ".\\MPC.ini");
  6.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "MERCHANTNAME", txtName.Text, ".\\MPC.ini");
  7.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "MERCHANTCODE", txtMerchantCode.Text, ".\\MPC.ini");
  8.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "SHOPID", txtShopID.Text, ".\\MPC.ini");
  9.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "TERMINALID", txtTerminalID.Text, ".\\MPC.ini");
  10.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "TEL", txtTel.Text, ".\\MPC.ini");
  11.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "FAX", txtFax.Text, ".\\MPC.ini");
  12.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "ADDRESS", txtAddress.Text, ".\\MPC.ini");
  13.                 IniFile.WritePrivateProfileString("MERCHANTINFO", "WEBSITE", txtWebsite.Text, ".\\MPC.ini");
  14.  
  15.                 Common.FuncShowInfoMsg("Merchant informations succesfully saved.", "Save Successful");
  16.  
  17.                 btnSave.Enabled = false;
  18.                 btnCancel.Text = "Close";
  19.                 btnCancel.Focus();
  20.  
  21.             }
  22.             catch (Exception ex)
  23.             {
  24.                 Common.FuncShowErrorMsg("Unable to save Merchant Info.", ex.Message, "Failed");
  25.             }
  26.         }
Reading ini file:
Expand|Select|Wrap|Line Numbers
  1. Common.sbName = new StringBuilder(1024);
  2.            Common.sbShopID = new StringBuilder(1024);
  3.            Common.sbTel = new StringBuilder(1024);
  4.            Common.sbTermID = new StringBuilder(1024);
  5.            Common.sbWebsite = new StringBuilder(1024);
  6.            Common.sbImageFileName = new StringBuilder(1024);
  7.            Common.sbFax = new StringBuilder(1024);
  8.            Common.sbAddress = new StringBuilder(1024);
  9.            Common.sbCode = new StringBuilder(1024);
  10.  
  11.            IniFile.GetPrivateProfileString("MERCHANTINFO", "MERCHANTNAME", "", Common.sbName, 1024, ".\\MPC.ini");
  12.  
  13.  
  14.            IniFile.GetPrivateProfileString("MERCHANTINFO", "MERCHANTCODE", "", Common.sbCode, 1024, ".\\MPC.ini");
  15.  
  16.  
  17.            IniFile.GetPrivateProfileString("MERCHANTINFO", "SHOPID", "", Common.sbShopID, 1024, ".\\MPC.ini");
  18.  
  19.  
  20.            IniFile.GetPrivateProfileString("MERCHANTINFO", "TERMINALID", "", Common.sbTermID, 1024, ".\\MPC.ini");
  21.  
  22.  
  23.            IniFile.GetPrivateProfileString("MERCHANTINFO", "TEL", "", Common.sbTel, 1024, ".\\MPC.ini");
  24.  
  25.  
  26.            IniFile.GetPrivateProfileString("MERCHANTINFO", "FAX", "", Common.sbFax, 1024, ".\\MPC.ini");
  27.  
  28.  
  29.            IniFile.GetPrivateProfileString("MERCHANTINFO", "ADDRESS", "", Common.sbAddress, 1024, ".\\MPC.ini");
  30.  
  31.  
  32.            IniFile.GetPrivateProfileString("MERCHANTINFO", "WEBSITE", "", Common.sbWebsite, 1024, ".\\MPC.ini");
  33.  
  34.  
  35.            IniFile.GetPrivateProfileString("MERCHANTINFO", "IMAGEPATH", "", Common.sbImageFileName, 1024, ".\\MPC.ini");
  36.  
Jun 10 '10 #1
0 1246

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
0
by: chris | last post by:
I'm writing a small app to help me learn more about cryptography. All it does is encrypt all of the files in directory A, and put the encrypted versions of the files in directory B. It then...
5
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got...
7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: Mika M | last post by:
I have made Setup and Deployment Project for my application. This application uses couble of Crysral Report .rpt -files, so I included following into Setup and Deployment Project ... -...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
5
by: littlemaster | last post by:
I have the following code, it is sending text message. I want to attach a file. How to do that? require 'net/smtp' # plain mail smtpclient = Net::SMTP::new( '192.168.1.1' ) # create new object to...
0
by: littlemaster | last post by:
The following program will send the mail with specified attachment file.Need to give the absolute path of the file. require "rubygems" require "ruport" require "ruport/util" r =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.