|
Dear Sid,
I am using this piece of code in thread.It tells me when client is connected and send data to me.
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 8001);
listener.Bind(endpoint);
listener.Blocking = true;
listener.Listen(0);
Socket objSock = listener.Accept();
objSock.Receive(ReceiveData);
objSock.Shutdown(SocketShutdown.Both);
listener.Close();
S.Akmal
|
|
|
|
|
dear Sid.
did u try the socket.connected property. It returns a boolean value either u r connected or disconnected.
Mr.Syed
|
|
|
|
|
I want to close the Client Socket ....Not the Listner(Server) how u r handeling Client Socket and Socket.Connected returns the previous state
its me sid
|
|
|
|
|
Send me the Exception text on socket.close().
S.Akmal
|
|
|
|
|
static void Main()
{
Application.Run(new Form1());
}
private System.Windows.Forms.GroupBox grpbox;
XPathDocument dom;
XmlDocument doc;
XPathNavigator nav;
XPathExpression expr;
XPathNodeIterator iterator;
int cnt=0;
Label lbl;
TextBox txt;
OpenFileDialog dlg;
TreeNode newTreeNode,rootnode,parentnode;
string text;
int i;
//int cnt = e.Node.GetNodeCount(false);
//string filename;
private void Form1_Load(object sender, System.EventArgs e)
{
//label1.Text = "File Path";
//label1.SetBounds(8, 8, 50, 20);
//filename = Application.StartupPath + "\\Sample.xml";
//textBox1.Text= filename;
//textBox1.SetBounds(64, 8, 256, 20);
button1.Text = "Populate the TreeView with XML";
button1.SetBounds(8, 20, 200, 20);
treeXml.Height = 600;
treeXml.Width = 400;
grpbox = new GroupBox();
grpbox.Height = 600;
grpbox.Width = 400;
grpbox.SetBounds(500, 2, 700, 600);
grpbox.Visible = true;
grpbox.Dock.Equals(Right);
grpbox.Show();
this.Controls.Add(grpbox);
//dom = new XPathDocument(dlg.FileName);
}
// it will acess the xml file into treeview
private void ConvertXmlNodeToTreeNode(XmlNode xmlNode,
TreeNodeCollection treeNodes)
{
TreeNode newTreeNode = treeNodes.Add(xmlNode.Name);
switch (xmlNode.NodeType)
{
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
newTreeNode.Text = "<?" + xmlNode.Name + " " +
xmlNode.Value + "?>";
break;
case XmlNodeType.Element:
if (xmlNode.Name.ToLower().Equals("node") == true)
{
newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">";
}
else
newTreeNode.Text = "<" + xmlNode.Name + ">";
break;
case XmlNodeType.Attribute:
newTreeNode.Text = xmlNode.Name;
// newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name;
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
newTreeNode.Text = xmlNode.Value;
break;
case XmlNodeType.Comment:
newTreeNode.Text = "<!--" + xmlNode.Value + "-->";
break;
}
if (xmlNode.Attributes != null)
{
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes);
}
}
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes);
}
}
// this is an event on which text box is created...
private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
cnt = e.Node.GetNodeCount(false);
grpbox.Controls.Clear();
for ( i = 0; i < cnt; i++)
{
Label lbl= new Label();
TextBox txt = new TextBox();
//lbl.Name="lbl"+i;
//lbl.Text="lbl"+i;
lbl.Text = e.Node.Text+i;
txt.Name="txt"+i;
txt.Text=txt.Name;
//txt.Text=e.Node.Text+i;
lbl.Left = 200;
lbl.Top = 200 * i;
txt.Left = 250;
txt.Top = 200 * i;
lbl.Show();
txt.Show();
grpbox.Controls.Add(txt);
grpbox.Controls.Add(lbl);
}
}
// this will open an6y xml file stored at your pc.
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
OpenFileDialog dlg = new OpenFileDialog();
treeXml.Nodes.Clear();
dlg.Title = "Open XML File";
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ;
if (dlg.ShowDialog() == DialogResult.OK)
{
//imgPhoto.Image = new Bitmap(dlg.OpenFile());
doc.Load(dlg.OpenFile());
}
dlg.Dispose();
ConvertXmlNodeToTreeNode(doc, treeXml.Nodes);
treeXml.Nodes[0].ExpandAll();
}
// insert a node
on this button click i want to a node in tree and thje value or string which is in the text box should add to the new treenode....
but this is not wornking,
private void button2_Click(object sender, System.EventArgs e ,TextBox txt)
{
TreeNode rootnode = treeXml.Nodes[0];
TreeNode parentnode = rootnode.Nodes[0];
newTreeNode = new TreeNode(txt.Text);
treeXml.SelectedNode.Nodes.Add(newTreeNode);
// if( treeXml.SelectedNode != null
parentnode = treeXml.SelectedNode;
parentnode.Nodes.Add(new TreeNode(txt.Text));
}
plz help me in this code.
modified on Thursday, February 07, 2008 1:30:10 AM
|
|
|
|
|
|
Hi,
I have learned how to load language specific string from sattelite assemblies by changing the CultureInfo of the Resource's typed class accessor. Now, I am wondering how can I set the culture specific language for the Microsoft's built in UI. For example, I want to change the language of the TextBox's context menu (Cut, Copy, Paste) as there is no "culture" property available for the class Control. Would you please give me any idea.
Thanks
|
|
|
|
|
use System.Globalization,
There, you will get Cultureinfo and RegionInfo Class.
just go through this.
you can also build custome culture using CultureAndRegionBuilder Class!!!
|
|
|
|
|
I'm trying to design my user interface where the user can change the background/foreground colors according to their preference. The XML file format appears to be the best and I would like any advice on making it as effecient as possible. The file's contents could change multiple times (re-written). Is overwriting XML file a good idea. Is there a better file format?
Thanks guys!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
programmingAddict wrote: Is overwriting XML file a good idea. Is there a better file format?
For reading and writing XML files, you can use XMLDocument class which provides a DOM model for the supplied XML file. This class provides methods for creating new node/attributes etc. For reading XML files efficiently, use XPath .
|
|
|
|
|
Thanks for the info. It will get me jump started. The more I look into XML, the more convinced I am that it's my best option. Some of the replies to this thread thought I was intending on the user writing the strings by hand
My opinion of user interaction with text is to limit the use of a textbox AS MUCH as possible! When the user gets a hold of a textbox that will be inputting critical data, bad things will start happening if serious validation is not done.
Best wishes to your code!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Depends on what you mean by 'better'.
Of course it is OK to overwrite an XML file. But if you want files that can be hand-edited by the user (think Notepad), .properties files are the way to go.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
Vikram A Punathambekar wrote: properties files
What is properties file ?
|
|
|
|
|
Very common in Javaland. Instead of angle brackets, they simply use the equals sign. Example:
dbServer=SERVERNAME
userName=user1 To the lay user, editing these in Notepad is much easier than editing XML files.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
That's fine. Is this commonly used in .NET ?
|
|
|
|
|
Why not use the standard .NET Profile Provider? It's not just for ASP.NET.
|
|
|
|
|
I have a windows application in C#. On click of a button i want to open windows Explore and navigate to one folder. How can i do that?
|
|
|
|
|
System.Diagnostics.Process.Start("C:\\Inetpub");
|
|
|
|
|
This should work for you:
System.Diagnostics.Process.Start(@"explorer.exe", @"C:\Windows");
Remember, google is your best friend!
Richard
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Hello Friends,
I am developing an windows application in C#.NET now i want that when i install that application in any machine then write into registry. If user wants to install it again then it check whether its entry is in registry or not if it found in registry then user unable to install it again.
Means once installed then unable to reinstall again until unless registry entry are removed....
|
|
|
|
|
Please let me know when find the answer because I need that feature in my app!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
I think you can write custom actions when creating installation package. This[^] blogs says something similar.
|
|
|
|
|
Make a setup of your application using VS IDE and use Registry Editor ...
|
|
|
|
|
Nouman Bhatti wrote: Make a setup of your application using VS IDE and use Registry Editor ...
can you elaborate on this?
|
|
|
|
|
as u said u r making your application in c# and hopefully for that u r using visual studio.
so in that same Visual studio there's a new project type "setup wizard" or "setup project" make your setup and when u done with it... there a option in that setup project with the name of Registry editor. u can add your required registry keys there.
|
|
|
|