|
Although it's not using the XmlTextReader, this should do what you want.
<br />
FileStream strmSettings;<br />
XmlDocument xmlDoc = new XmlDocument();<br />
XmlNode nSetting;<br />
string filePath;<br />
<br />
strmSettings = File.Open("options.xml", FileMode.Open);<br />
xmlDoc.Load(strmSettings);<br />
<br />
nSetting = xmlDoc.SelectSingleNode("/options");<br />
if(nSetting != null)<br />
filePath = nSetting.InnerText;<br />
<br />
strmSettings.Close();<br />
The string filePath will now contain the value from the Xml so you can do this:
<br />
XmlTextWriter writer = new XmlTextWriter(filePath + fileName, null);<br />
Obviously you should do some more error checking, but in the interests of simplicity this should get you up and running.
HTH
|
|
|
|
|
I FIGURED IT OUT! Thanks for you help...
It took me a while but, after tweeking you code out a little and a crash course on xml thanks to MSDN I got it.
XmlDocument xmlDoc = new XmlDocument();
XmlNode nSetting;
string filePath;
xmlDoc.Load("options.xml");
nSetting = xmlDoc.SelectSingleNode("//Options/entryFile");
filePath = nSetting.InnerText;
string fileName = DateTime.Now.ToString("yyyyMMdd_hhmm") + ".xml";
XmlTextWriter writer = new XmlTextWriter(filePath + fileName, null);
I probably ghetoed this code out alot... but it works... I'll work on cleaning it up later... thanks agian!
/\ |_ E X E GG
|
|
|
|
|
Hey
I have the folowing cod:
try
{
//reading of logg file
StreamReader srlogg = new StreamReader(Application.StartupPath + "\\logg.bin",false);
BinaryFormatter bfstat = new BinaryFormatter();
arylogg = (ArrayList)bfstat.Deserialize(srlogg.BaseStream);
srlogg.Close();
}
catch.........
How could i do to avoid a message box that says error, the file .... .not found.
I fought first that srlogg maby sets to null when no file is not found, but the error comes already on the
StreamReader srlogg = new........
row, is there a good way to avoid error messages only for a file that are missing? I whant the try and catch if there will be other errors.
PS:
When the program starts, then all files is loaded, then thay ar updated after every change.
Best regards
Jimmy
|
|
|
|
|
You should be using a Stream derived class for the BinaryFormatter, not a TextReader derived class like you are using at the moment.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
if ( System.IO.File.Exists( Application.StartupPath + @"\logg.bin" ) )
{
...
}
|
|
|
|
|
Since the Winforms dialog controls do not allow must in the way of customizing (e.g. customizing the OpenFileDialog), I was wondering if anyone has seen any commercially available 3rd party controls that provide customized dialogs. I thought I've seen some one time on the web, but a google search hasn't helped me find it again.
Anyone?
mr
(this is a dup. of my post in the .Net Framwork forum, since I couldn't change the forum after the message was posted.)
|
|
|
|
|
|
Hi,
does somebody know about a native C# Control which is similiar to the outlook view of mails if you choose "View\Sort by Sender" ?
.:Greets from Jerry Maguire:.
|
|
|
|
|
There is a sorted listbox[^] on CP which may be what you're looking for.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I have a simple project where I've derived my own class from System.Windows.Forms.TextBox. Then, in the same project, I created a form, added a textbox to it, and changed the type from TextBox to MyTextBox (my class name). It all compiles and builds fine. But when I try to open the form in Design mode, I get an error:
System.Runtime.Serialization.SerializationException: Could not find type 'MyTextBox'. Please make sure that the assembly that contains this type is referenced. If this type is a part of the your development project, make sure that the project has been successfully built.
Then the form appears without the textbox on it. How can I solve this problem?
Thanks in advance!
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Never do what you just described.
1.If your custom textbox is defined within a class in the project, the best thing you can do is to add your derived textbox programmatically, i.e.,
MyTextBox mtb=new MyTextBox;<br />
<br />
mtb.Location=...
2. In order to be able to visually use your derived textbox at design-time, you must build your custom textbox as a user control. That way you will be able to reference it and put it in the toolbox.
|
|
|
|
|
I want to set version information for my c# application and then be able to extract it and display it in a about box at runtime.
Some of the information I need you can define in the assemblyinfo file associated with a solution
eg.
[assembly: AssemblyTitle("Gradient Volume Calculator")]
[assembly: AssemblyDescription("Solvent Calculator for use by AS Software")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("XYZ")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("© XYZ")]
[assembly: AssemblyTrademark("XYZ")]
[assembly: AssemblyCulture("")]
and then access it using the FileVersionInfo command below
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(sFilePath);
x := myFileVersionInfo.LegalCopyright.ToString();
You can also Get Productname, FileVersion and InternalName, etc.
But HOW do you set things like ProductName, FileVersion, InternalName, FileDescription and Comments.
Am I missing an assembly reference or something?
Thanks in advance
Satvinder Basra
|
|
|
|
|
Looks like the attribute names not match up with the VersionInfo string names directly. Here are a few I mapped out:
ProductName = [assembly: AssemblyProduct()]
ProductVersion = [assembly: AssemblyInformationalVersion()]
FileVersion = [assembly: AssemblyFileVersion()]
Commants = [assembly: AssemblyDescription()]
Burt Harris
|
|
|
|
|
program mystery
String x;
Boolean f;
integer a, z,g;
x = readinput
g = length of x
z = g minus one;
a = zero
if g = 1 then f = 1
else
f = 1;
while (f=1 and a less than z)
while character at a of x is one of [whitespace,comma,semicolon, or full stop]
a++;
while character at z of x is one of [whitespace,comma,semicolon, or full stop]
z--;
if the toUpperCase of character at a of x is identical to
the toUpperCase of character at z of x
then a++ and z--;
else f=0;
if f=0 then print out appropriate message
else print out other appropriate message
any help would be apreciated cheers tom
|
|
|
|
|
Why not write it?
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
public void DoesSomethingIKnowNotWhat()
{
string x;
bool f;
int a, z, g;
x = Console.ReadLine ();
g = x.Length;
z = g - 1;
a = 0;
if (g == 1)
{
f = 1;
}
else
{
f = 1;
}
while (f = 1 && a < z)
{
while (x.Substring (a, 1) == " " ||
x.Substring (a, 1) == ";" ||
x.Substring (a, 1) == ".")
{
a++;
}
while (x.Substring (z, 1) == " " ||
x.Substring (z, 1) == ";" ||
x.Substring (z, 1) == ".")
{
z--;
}
if (x.Substring (a, 1).ToUpper () ==
x.Substring (z, 1).ToUpper ())
{
a++;
z--;
}
else
{
f = 0;
}
}
if (f == 0)
{
Console.WriteLine ("Appropriate message");
}
else
{
Console.WriteLine ("Other appropriate message");
}
}
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Is there a nices way than this:
System.IO.Stream stream = irdaClient.GetStream();
int msglength = System.Net.IPAddress.HostToNetworkOrder(textBox1.Text.Length);
byte[] length = new byte[4];
length[0] = (byte)((msglength >> 0 ) & 0x000000FF);
length[1] = (byte)((msglength >> 8 ) & 0x000000FF);
length[2] = (byte)((msglength >> 16) & 0x000000FF);
length[3] = (byte)((msglength >> 24) & 0x000000FF);
stream.Write(length, 0, length.Length);
I think that the way with the byte array is not very nice! I think it's ugly !
The stream is a IrDA connection!
I have tried the StreamWriter class, but that doesn't work! The Server-Application receives some wrong things!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
If all you are trying to do is put the bytes of the int into the stream, why not use a BinaryWriter ?
This class has many overloads for Write().
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks! I will try it!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Hi there
I wonder how you play sounds(mp3) in C# in a good way?
|
|
|
|
|
It's possible to control WinAmp in order to play mp3s. There is some dll which allows you to do so.
Decoding mp3s is quite difficult I think and I read that you need an expensive licence to be able to access information about the internal format of mp3s. But I'm not quite sure
But WinAmp is freeware...
|
|
|
|
|
I made a ComboDataGrid (ParentControl). When the ComboBox (ChildControl) in the DataGrid has the Focus then I want to catch any Key Events from the ComboBox.
The ComboGrid should react as follows:
When the focused cell is not the ComboBoxColumn then the DataGrid should act normal, what means when the user presses Up or Down Arrows, the Focused Row chould change.
When the focused cell is in a ComboBoxColumn then it should be possible to press Ctrl+Up or Down Arrow to scroll up and down in the ComboBox.
To solve this I need any keyEvent of the ComboBox before the DataGrid. I tried with ProcessCmdKey(), ProcessKeyEventsArgs() but could not get what I wanted.
Big Thanks for all who will reply.
Stefan
|
|
|
|
|
I made a ComboDataGrid (ParentControl). When the ComboBox (ChildControl) in the DataGrid has the Focus then I want to catch any Key Events from the ComboBox.
The ComboGrid should react as follows:
When the focused cell is not the ComboBoxColumn then the DataGrid should act normal, what means when the user presses Up or Down Arrows, the Focused Row chould change.
When the focused cell is in a ComboBoxColumn then it should be possible to press Ctrl+Up or Down Arrow to scroll up and down in the ComboBox.
To solve this I need any keyEvent of the ComboBox before the DataGrid. I tried with ProcessCmdKey(), ProcessKeyEventsArgs() but could not get what I wanted.
Big Thanks for all who will reply.
Stefan
|
|
|
|
|
I am considering taking the plunge, and designing my first full fledged application in C# (WinForms). It will have a MDI and lots of menus and right click events.
What is the best way to fully plan out my design before coding? Besides the needs and must haves of the app, is there anything else i should take into consideration?
- I will be doing most of this with Visio, along with the trusty ol' pen & paper;)
Thanks,
Steve
McLenithan
Is Bert Evil?
|
|
|
|
|
Not to be silly but why not start by writing out a few use cases?
Also, if you can, try to avoid cramming all of your code into the On_Click() etc. style event methods as it tends to make the code less extensible and reusable. Invest some time into looking at using patterns like the "Command", "Mediator", "Event-Delegate/observer".
Also, look at Marc Clifton's AAL which is posted here on codeproject.
Some MS links are
http://msdn.microsoft.com/architecture/patterns/
http://msdn.microsoft.com/architecture/community/
Misc Links
http://www.cs.mu.oz.au/~moke/
And a discussion on GotDotNet
http://www.gotdotnet.com/community/messageboard/Thread.aspx?id=83782
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|