Tom Knowlton
asked on
INI file
What is an easy way to write-out and read-in basic Form initialization data?
For example...whenever the form closes....I want to record the form height and form width to some sort of INI file.
Then when the form opens it will read-in the INI file and set the form height and width to whatever it was last set to in the INI file.
Is there a "best practice" for doing this sort of thing?
For example...whenever the form closes....I want to record the form height and form width to some sort of INI file.
Then when the form opens it will read-in the INI file and set the form height and width to whatever it was last set to in the INI file.
Is there a "best practice" for doing this sort of thing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmmm....
I am trying to implement a simple XML Serializer / Deserializer:
using System;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplicationXML
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Serialize();
Deserialize();
Console.ReadLine();
}
static public void Serialize()
{
ClassXML cxml = new ClassXML();
XmlSerializer mySerializer = new XmlSerializer(typeof(Class XML));
StreamWriter myWriter = new StreamWriter("tomtestxmlto day.xml");
myWriter.Flush();
myWriter.Close();
}
static public void Deserialize()
{
ClassXML cxml = new ClassXML();
XmlSerializer mySerializer = new XmlSerializer(typeof(Class XML));
FileStream myFileStream = new FileStream("tomtestxmltoda y.xml",Fil eMode.Open );
cxml = (ClassXML)mySerializer.Des erialize(m yFileStrea m);
Console.WriteLine(cxml.Fir stName);
Console.WriteLine(cxml.Las tName);
myFileStream.Close();
}
}
}
and the ClassXML:
using System;
namespace ConsoleApplicationXML
{
/// <summary>
/// Summary description for ClassXML.
/// </summary>
public class ClassXML
{
public string FirstName;
public string LastName;
public ClassXML()
{
//
// TODO: Add constructor logic here
//
FirstName = "Tom";
LastName = "K";
}
}
}
What am I doing wrong?
An unhandled exception of type 'System.InvalidOperationEx ception' occurred in system.xml.dll
Additional information: There is an error in XML document (0, 0).
The program '[2684] ConsoleApplicationXML.exe' has exited with code 0 (0x0).
Am I missing an attribute in the ClassXML?? [XmlAttrubute] or something?
I am trying to implement a simple XML Serializer / Deserializer:
using System;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplicationXML
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Serialize();
Deserialize();
Console.ReadLine();
}
static public void Serialize()
{
ClassXML cxml = new ClassXML();
XmlSerializer mySerializer = new XmlSerializer(typeof(Class
StreamWriter myWriter = new StreamWriter("tomtestxmlto
myWriter.Flush();
myWriter.Close();
}
static public void Deserialize()
{
ClassXML cxml = new ClassXML();
XmlSerializer mySerializer = new XmlSerializer(typeof(Class
FileStream myFileStream = new FileStream("tomtestxmltoda
cxml = (ClassXML)mySerializer.Des
Console.WriteLine(cxml.Fir
Console.WriteLine(cxml.Las
myFileStream.Close();
}
}
}
and the ClassXML:
using System;
namespace ConsoleApplicationXML
{
/// <summary>
/// Summary description for ClassXML.
/// </summary>
public class ClassXML
{
public string FirstName;
public string LastName;
public ClassXML()
{
//
// TODO: Add constructor logic here
//
FirstName = "Tom";
LastName = "K";
}
}
}
What am I doing wrong?
An unhandled exception of type 'System.InvalidOperationEx
Additional information: There is an error in XML document (0, 0).
The program '[2684] ConsoleApplicationXML.exe'
Am I missing an attribute in the ClassXML?? [XmlAttrubute] or something?
ASKER
When I try and open the XML file in a browswer it says:
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
XML document must have a top level element. Error processing resource 'file:///R:/IsElectDev/Ele ctronics/D ev/Topaz/S oftware/Cl ient/ISDri llInfo/Con soleApplic ationXML/b in/Debug/t omtestxmlt oday.xml'.
I don't think my Serialize( ) method call is working.
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------
XML document must have a top level element. Error processing resource 'file:///R:/IsElectDev/Ele
I don't think my Serialize( ) method call is working.
I think your're missing something :)
mySerializer.Serialize(myW riter, cxml);
before you flush/close the file (flush isn't needed here)
+ you're really serializing an EMPTY class, i.e. you just created it before you're writing it; that doesn't make much sense, but I assume you're testing :)
If you want to take a look at the "raw" xml file, you can also open it in Notepad.
mySerializer.Serialize(myW
before you flush/close the file (flush isn't needed here)
+ you're really serializing an EMPTY class, i.e. you just created it before you're writing it; that doesn't make much sense, but I assume you're testing :)
If you want to take a look at the "raw" xml file, you can also open it in Notepad.
ASKER
>>>>>I think your're missing something :)
>>>> mySerializer.Serialize(myW riter, cxml);
>>>>>before you flush/close the file (flush isn't needed here)
=========================
You mean the compiler can't read minds?
Yes, that was it....I missed that line while copying from an XML example on MSDN.....sheeesh.
It's working now.....
>>>> mySerializer.Serialize(myW
>>>>>before you flush/close the file (flush isn't needed here)
=========================
You mean the compiler can't read minds?
Yes, that was it....I missed that line while copying from an XML example on MSDN.....sheeesh.
It's working now.....
perfect :) - I thought that mind reading part was finally added in vs2003, but I guess we'll have to wait for vs2005 (or possibly later) :))
ASKER
cookre:
>>I don't want to rely on the Registry.
Just about everything else does.
Besides, if you save info under HKCU, you have user specific saves.
========================== ========== ========== =======
This is a really good point.
>>I don't want to rely on the Registry.
Just about everything else does.
Besides, if you save info under HKCU, you have user specific saves.
==========================
This is a really good point.
ASKER
>>>>perfect :) - I thought that mind reading part was finally added in vs2003, but I guess we'll have to wait for vs2005 (or possibly later) :))
LOL.....
Those Microsoft Slackers!!!!!
LOL.....
Those Microsoft Slackers!!!!!
ASKER