473,671 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File problems

i have a program that reads through an ini file and does stuff so far
the only thing i am having trouble with is the writing to the ini
file. if the section is alreadey there i want to do a search for that
line then all text to the next line of end of that block can someone
help with this.
Nov 15 '05 #1
4 3121
Shane,

Are you doing this parsing yourself? Have you considered using the
WritePrivatePro fileString/WritePrivatePro fileSection API functions? You can
call these to write your INI file sections, and you can use the
ReadPrivateProf ileString/ReadPrivateProf ileSection API functions to read the
same INI file.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Shane Mergy" <mo***@ameritec h.net> wrote in message
news:41******** *************** ***@posting.goo gle.com...
i have a program that reads through an ini file and does stuff so far
the only thing i am having trouble with is the writing to the ini
file. if the section is alreadey there i want to do a search for that
line then all text to the next line of end of that block can someone
help with this.

Nov 15 '05 #2
You should better use a class specially for settings. This class must be
Serializable

This is an exapmle that saves and retrievs the setting for the font size of
a textBox in a file

-----------Settings Class---------------
using System;

[Serializable]

public class settingsClass

{

public settingsClass(f loat size,int delay)
{

fontSize=size;

programDelay=de lay;

}

#region Font Size

private float fontSize;

public float FontSize

{

get

{

return fontSize;

}

set

{

fontSize=value;

}

}

#endregion Font Size

}


-----------loadSaveSetting sClass--------------------------------
using System.IO;
using System.Drawing;
using System.Runtime. Serialization.F ormatters.Binar y;

public class loadSaveSetting sClass
{
public loadSaveSetting sClass(main mf)
{
mainForm=mf;
}

private static main mainForm;

private static BinaryFormatter binaryFormatter = new BinaryFormatter ();

private static FileStream fileStream;
private static settingsClass settings;

#endregion ???????? ??????????
public static void loadSettings()
{
settings=new settingsClass(0 ,0);

string fileName=(strin g)mainForm.Prog ramDirectory+"\ \settings.dat";

try
{
fileStream=new FileStream(file Name,FileMode.O pen,FileAccess. Read);
settings=(setti ngsClass) binaryFormatter .Deserialize(fi leStream);
}

catch (System.IO.File NotFoundExcepti on)
{
return;
}

catch (System.Runtime .Serialization. SerializationEx ception)
{
fileStream.Clos e();
return;
}

fileStream.Clos e();

mainForm.source Code.Font=new
Font(mainForm.s ourceCode.Font. FontFamily,sett ings.FontSize);
}

public static void saveSettings()
{
settings = new
settingsClass(m ainForm.sourceC ode.Font.Size,m ainForm.delayTr ackBar.Value);

string fileName=(strin g)mainForm.Prog ramDirectory+"\ \settings.dat";

fileStream=new
FileStream(file Name,FileMode.O penOrCreate,Fil eAccess.Write);

binaryFormatter .Serialize(file Stream,settings );

fileStream.Clos e();
}
#endregion Save Setting
}
"Shane Mergy" <mo***@ameritec h.net> wrote in message
news:41******** *************** ***@posting.goo gle.com...
i have a program that reads through an ini file and does stuff so far
the only thing i am having trouble with is the writing to the ini
file. if the section is alreadey there i want to do a search for that
line then all text to the next line of end of that block can someone
help with this.

Nov 15 '05 #3


how would i do this
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
Shane,

Here is the declaration for WritePrivatePro fileString:

[DllImport("kern el32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
public static extern bool WritePrivatePro fileString(
[MarshalAs(Unman agedType.LPTStr )] string lpAppName,
[MarshalAs(Unman agedType.LPTStr )] string lpKeyName,
[MarshalAs(Unman agedType.LPTStr )] string lpString,
[MarshalAs(Unman agedType.LPTStr )] string lpFileName);

And here is the declaration for WritePrivatePro fileSection:

[DllImport("kern el32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
public static extern bool WritePrivatePro fileSection(
[MarshalAs(Unman agedType.LPTStr )] string lpAppName,
[MarshalAs(Unman agedType.LPTStr )] string lpString,
[MarshalAs(Unman agedType.LPTStr )] string lpFileName);

You will have to have the "using System.Runtime. InteropServices ;"
directive at the top of the file as well.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com

"Shane Mergy" <mo***@ameritec h.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..


how would i do this
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2174
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
12
2967
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this and not have it affected by the null? because it is right now causes truncated data at wierd places... but as soon as i manually with a hex editor change char(00) to char(20) in the files it reads prerfectly... which leads me to my 2nd...
8
9745
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
5
6454
by: Claudio Grondi | last post by:
I have just started to play around with the bsddb3 module interfacing the Berkeley Database. Beside the intended database file databaseFile.bdb I see in same directory also the __db.001 __db.002 __db.003 files where
7
12230
by: ashley.ward | last post by:
We have been using VB6 to develop small custom apps that access an Oracle database, in order to extend a larger product that is developed by our colleagues in Germany (who use C++ and Java). As each app is small and simple, we have been distributing each to the customer in the form of a single EXE file. I have been attempting to build another one of these small custom apps, using VB 2005 Express Edition. It doesn't seem to be possible...
2
1239
by: Jack Fox | last post by:
We are encountering a couple of problems with our ASP.NET / IIS 6.0 applications: In each of 3 production environments we maintain a Windows Server 2003 machine running NTFS as a file server. The file server typically has 10s of thousands of files on it. We've nver bothered to count, but I can imagine that some environments excede 100,000 files. Problem #1) We use the HttpContext Cache with a dependency on some given file on the file...
1
6478
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
29
4857
by: list | last post by:
Hi folks, I am new to Googlegroups. I asked my questions at other forums, since now. I have an important question: I have to check files if they are binary(.bmp, .avi, .jpg) or text(.txt, .cpp, .h, .php, .html). How to check a file an find out if the file is binary or text? Thanks for your help.
34
5339
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2813
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.