|
I'm having problems with the following code snippet. It executes the first Messagebox within the foreach, but then fails at the if just beneath that.
Can anyone help please.
foreach(XmlNode node in settingNode.ChildNodes)
{
System.Windows.Forms.MessageBox.Show("Inside foreach","Entered");
if(node.Attributes["key"].Value != null)
{
System.Windows.Forms.MessageBox.Show(node.Attributes["key"].Value,"Value");
if(node.Attributes["key"].Value == "ServerName")
{
System.Windows.Forms.MessageBox.Show("Saving Servername","Servername");
NumNode = node;
XmlAttribute att = NumNode.Attributes["value"];
att.Value = ServerName;
doc.Save(appConfigPath);
System.Windows.Forms.MessageBox.Show("Finished ServerName","Servername");
}
if(node.Attributes["key"].Value == "DBName")
{
System.Windows.Forms.MessageBox.Show("Saving dbName","dbname");
NumNode = node;
XmlAttribute att = NumNode.Attributes["value"];
att.Value = DBName;
doc.Save(appConfigPath);
System.Windows.Forms.MessageBox.Show("Finished dbname","dbname");
}
if(node.Attributes["key"].Value == "UserID")
{
System.Windows.Forms.MessageBox.Show("Saving UserId","UserId");
NumNode = node;
XmlAttribute att = NumNode.Attributes["value"];
att.Value = UserID;
doc.Save(appConfigPath);
System.Windows.Forms.MessageBox.Show("Finished UserId","UserId");
}
if(node.Attributes["key"].Value == "Password")
{
System.Windows.Forms.MessageBox.Show("Saving password","password");
NumNode = node;
XmlAttribute att = NumNode.Attributes["value"];
att.Value = Password;
doc.Save(appConfigPath);
System.Windows.Forms.MessageBox.Show("Finished password","password");
}
}
}
|
|
|
|
|
Howdy folks,
I want to learn about developing and using COM+ objects within the .NET world. Can anyone point me in the right direction? Online tutorials or articles? Good books?
thanks,
paully
|
|
|
|
|
|
Hello all!
I am using a C# program and would like to generate the C# application (window application), after compile an exe file from the source code. Can anyone provide some help. I look for msdn but not found.
Thanks All,
Tran Dung
|
|
|
|
|
You can try using System.CodeDom. It allows you to build dynamic assemblies. But its bit complex.
Best Regards
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
hi... i have a problem regarding my transaction number... i make it a randomized one, but what i really want is to make it a...
example: my transaction number now is 000121 then after that transaction it will automatically turn into 000122... is that posible. could you teach me how... THANKS
Chill out!!!
|
|
|
|
|
What kind of transaction are you talking about? SQL transactions? System.Transactions? Client/server transactions?
|
|
|
|
|
So what you want to do is to auto increment the transactions number, with the transaction number being a variable within your code.
If I understand correctly.
Do you only use the app or do you use sql with your app?
I would say that if its just within your app the best would be
int trans = 0;
Number++;
or if you use sql you can set that each new entry must be unique and auto increment where you can specify the starting point and the amount with wich to increment.
|
|
|
|
|
Hi, I'm a newbie at C#, I was wondering if there was a code for knowing the location of the current open C# document. Let's say I want to know the location(In string form) of Form1.cs, is there any code to represent this?
Thank you very much
|
|
|
|
|
Can you be more specific? The opened C# file...are you trying to find out the file path of a C# file Visual Studio has opened?
|
|
|
|
|
Yes. Because I want to access a folder that is located in the same folder as the file but I can't seem to access it.
it looks like this:
Folder1 contains
-Form1.cs
-FolderIwantToAccess contains pic.bmp
I want to access pic.bmp from Form1.cs
Thanks a lot!
-- modified at 22:35 Monday 6th February, 2006
|
|
|
|
|
Your .cs file doesn't execute directly. It gets compiled into your .exe file located in your \bin\debug\ directory. So your C# code will want to locate the bitmap relative to that directory.
If your directory structure is
MyProject
-FolderIWantToAccess
-bin
-Debug
Then you can access the image from your app using "..\\..\\FolderIWantToAccess\\pic.bmp"
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I tried it but the program still doesnt read the picture file...I want to access the pic.bmp without directly enforcing the complete filepath (e.g. c:\mydocuments\sample\project\folderiwanttoaccess\pic.bmp <--i dont want to write this in the program source file...)
|
|
|
|
|
I understand what you're trying to do.
You can access files in a higher directory level that the exe using "..\\". So if your .exe file is running from c:\mydocuments\sample\project\bin\debug\test.exe, you can locate the image from your C# code using
// Adjust the line below depending on how many parent directories must be navigated upwards to read the folderIWantAccessTo directory.
stromg pathToImage = "..\\..\\..\\folderIWantAccessTo\pic.bmp";
If you want to see what's going on with those "..\\" things, see what this returns:
string path = Path.GetFullPath("..\\..\\..\\");
It should return your project root. From there the rest is easy, just append the folderIWantAccessTo\pic.bmp to the end of the string and you're good.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I figured out what was lacking in your idea... there should be three "." instead of two. It is now working correctly. Thanks very much
|
|
|
|
|
|
ei guys... i'm having a problem in printing the receipt for my point of sale. Just want to ask you... what tools should i used for the reciept and maybe some codes in printing it... thanks
|
|
|
|
|
Most printers are graphics printers. I have found that I can create class that builds the receipt as an image then send it to the printer. The api's are usually availiable from the mfg to configure the printer and they will give you examples.
I went this direction because getting text lined up is pretty difficult and in the end just looks bad.
|
|
|
|
|
How can i make documentation(*.chm) to descript my dll after build.
Nothing
|
|
|
|
|
|
How about Doxygen,
generate hhp, then Chm
|
|
|
|
|
Hi,
Can you show me any snippet or any library in order to extract text from RTF file ( or you can say, convert RTF file to txt file) PLeaseeeee
Emran
|
|
|
|
|
Hi,
Use rich text box control.
It has a rtf property to which you should set the rtf code and then in the text property of the rich text box you will get the plain code.
But If u want a function or something then sorry I don't know.
Jayvardhan Patil
|
|
|
|
|
I am attempting to write a method to iterate through a xml file that has multiple nodes that match a given type but for some reason it only accepts the first one and then exists. I think I may have my loop wrong or something. Can anyone tell me what the issue may be?
using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
using System.Threading;
namespace UTS_Batch_Update
{
public class UTSB_Input
{
{
string Path = "C:\\xmlticketID.xml";
// If the user forgets to put in a path, throw a NullException.
if (Path == null)
{
throw new ArgumentNullException();
}
// Load the document.
XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(Path);
// Retrieve each ticketID.
//XmlNodeList tickets = sourceDoc.GetElementsByTagName("TicketId");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(sourceDoc.NameTable);
foreach (XmlNode node in tickets)
if (node.Name == "TicketId")
{
//using (MemoryStream buffer = new MemoryStream())
string buffer = "c:\\xmlpost.xml";
XmlTextWriter w = new XmlTextWriter(buffer, null);
// Start the document.
w.WriteStartDocument();
w.WriteStartElement("XMLFILE");
w.WriteAttributeString("UserLogName", "REDMOND\\" + UserInfo);
w.WriteAttributeString("FileId", "MSN Search BUU");
w.WriteAttributeString("Action", "Close");
w.WriteStartElement("TICKET");
w.WriteAttributeString("TicketId", node.InnerXml.ToString());
w.WriteAttributeString("CloseControlInd", "No");
w.WriteAttributeString("ProblemResolved", Resolved);//ConvertBoolToYesNo(Resolved));
w.WriteAttributeString("WereProceduresInPlace", ProceduresInPlace);
w.WriteAttributeString("WereProceduresInPlaceNotes", ProceduresInPlaceNotes);
w.WriteAttributeString("WereProceduresAccurate", ProceduresAccurate);
w.WriteAttributeString("WereProceduresAccurateNotes", ProceduresAccurateNotes);
w.WriteAttributeString("WereToolsEffective", ToolsEffective);
w.WriteAttributeString("WereToolsEffectiveNotes", ToolsEffectiveNotes);
w.WriteAttributeString("FalseAlarmInd", FalseAlarm);
w.WriteAttributeString("VerifiedBy", VerifiedBy);
w.WriteAttributeString("NotifyAliases", NotifyAliases);
w.WriteAttributeString("ClosureNotes", Closure);
w.WriteEndElement();
// End the document.
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
w.Close();
XmlTextReader reader = new XmlTextReader(buffer);
XmlDocument outputDoc = new XmlDocument();
outputDoc.Load(reader);
string processpath = "C:\\WINDOWS\\system32\\wscript.exe";
string processargs = "C:\\uts.wsf c:\\xmlpost.xml";
System.Diagnostics.Process.Start(processpath, processargs);
return outputDoc;
}
throw new InvalidOperationException("No XML was converted.");
}
} // end method UTSBFileLoad
}
|
|
|
|
|
dbenisch wrote: I think I may have my loop wrong or something.
Yes, you have. You have the return statement inside the loop.
---
b { font-weight: normal; }
|
|
|
|