|
Hve you consodered For Each TextBox ?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
No no.
1. For Each is VB, not C#
2. Form.Controls holds all top-level Controls of the Form, no matter what type they are; if one of them isn't a TextBox, foreach will fail to cast it and throw an exception, it does not enumerate just the derived type one is interested in!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
hi All, I am having trouble doing some string manipulation. I get a string with coma delimited. I want remove the first portion of the string.
for example,strMessage = " I, Have, a, string, that, describe, something"
what I want to do is that remove the first coma delimited part of the variable strMessage so it look like this
"Have, a, string, that, describe, something" how do I do this. Any help appreciated.
then I insert the string in my datagridview.
datagridview.Rows.Insert(0,strMessage.Split(','))
I want to keep this style of inserting into dataGridView just want to remove the first portion of the string which is "I".
thanks
|
|
|
|
|
string.Split() is the method you want; it has a few overloads, so I refer to its documentation.
BTW: you won't solve problems any faster by putting as much as possible into a single statement. Split things up, and look at the intermediate values while debugging.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
this is quite simple for the case you stated. That is just the first comma.
Use IndexOf. Something like:
str.Substring(str.IndexOf(",") + 1).TrimStart();
All the best,
Dan
|
|
|
|
|
Here[^] is the solution to all your problems.
(Well the ones about splitting, personal probelms are chargeable).
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
string[] parts = strMessage.Split(",");
for (int i = 0; i < parts.Length; i++)
{
parts[i] = parts[i].Trim();
}
dataGridView.Rows.Insert(0, parts);
But don't you need to ensure that the number of parts matches the number of columns you have in the row?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hi,
I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File.
How can I import the data from my xml File to copy them in the specified file choosen by the user of my application????
Thank u very much
modified on Friday, March 11, 2011 5:33 AM
|
|
|
|
|
Good question.
Here is how i did. Suppose user selects the path like this :
Path="C:\MyFile.xml";
Suppose you have an object of xmlDoc containing the xml.
So now we have to create a Filestream for the new path, and then use the StreamWriter class to write the xml to the new path.
FileStream fs=new FileStream(path,FileMode.Create,FileAccess.ReadWrite);
StreamWriter sw=new StreamWriter(fs,Text.Encoding.UTF8);
sw.Write(xmlDoc.OuterXml);
sw.Close();
fs.Close();
Hope it helped!
People with high attitude deserve the standing ovation of our highest finger!
My Technical Blog![ ^]
|
|
|
|
|
Hi,
I don't understand what u mean xmldoc.outerxml??? xmldoc is is my xml document?
ty
|
|
|
|
|
xmlDoc is an object of XmlDocument. It will contain your MyFile.xml .
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(@"C:\Documents and Settings\My Documents\Visual Studio\MyFile.xml");
and xmlDoc.OuterXml will give you the whole contents of the xml which will be used to write to the new file.
People with high attitude deserve the standing ovation of our highest finger!
My Technical Blog![ ^]
|
|
|
|
|
Hi Tarun,
Fine my file is well copied but the problem all tags appear in the same ligne.
How can i get an organized xml file well organized (tags organized)like this:
<GrpHdr>
<MsgId>DOSSIER1</MsgId>
<CreDtTm>2011-03-07T10:39:29</CreDtTm>
<BtchBookg>True</BtchBookg>
<NbOfTxs>2</NbOfTxs>
<CtrlSum>5534,4</CtrlSum>
<Grpg>MIXD</Grpg>
<InitgPty>
<Nm>Dossier1</Nm>
</InitgPty>
</GrpHdr>
As I conclude, it reads them string.
How can I solve that?
ty
|
|
|
|
|
I will get back to you on this as soon as i find the solution.
People with high attitude deserve the standing ovation of our highest finger!
My Technical Blog![ ^]
|
|
|
|
|
Hi,
even if I use Text.Encoding.UTF8 the file still not organized like an xml File format.
Thank u for u help on this (still waiting for u help )
|
|
|
|
|
hello Turan,
I found a solution. i just add the text.encoding UTF-8 to my code:
this.Response.ContentEncoding = Encoding.GetEncoding ("UTF-8");
I open my file with an Xml editor all works fine and my File is well structred.
Thank u a lot for u help and I am now sssssssssssssssso happy.
|
|
|
|
|
Awesome!
People with high attitude deserve the standing ovation of our highest finger!
My Blog![ ^]
|
|
|
|
|
If you are already generating the document in your application then why would you need to import it again. Just save it to where the user wants it when you generate it, rather than saving it to your application directory.
If you want to prompt the user for a save location then use the SaveFileDialog[^]
Also, if you want to just copy a file from one location to another then use System.IO.File.Copy()
I may or may not be responsible for my own actions
|
|
|
|
|
Hi,
I need to read Remote server Directories through FTP Credentials and bind remote directory
structure to Tree View Control.
Please suggest me better way.
Regards,
Vishnu.
|
|
|
|
|
Use FTPWebRequest[^] class. You can get the directory list from here and create your treeview based on that
I may or may not be responsible for my own actions
|
|
|
|
|
Hi,
I tried with above link but it is not working .Please suggest me better way.
Regards,
Vishnu.
|
|
|
|
|
What is not working... show some code.
If it is not working, then a better way would be to make it work
I may or may not be responsible for my own actions
|
|
|
|
|
Hi,
I tried with below code and i'm getting only root directories not sub directories , i need to get sub directories
please suggest me better way.
string ftpServerIP = "75.125.2.193";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ftpServerIP + "/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential("barikgr2", "barik122");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string line;
while ((line = reader.ReadLine()) != null)
{
TreeNode node = new TreeNode();
string[] _arv = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
node.Text = _arv[3];
treeView1.Nodes.Add(node);
}
reader.Close();
response.Close();
Regards,
Vishnu.
|
|
|
|
|
Hi,
My code below is in a windows service:
Can you see from the code here, why the backgroundworker_DoWork only gets called once?
I expect it to be called every 200 milliseconds.
There is a timer which gets called every few seconds i.e. OnElapsedTime which does other checks.
But I am trying to have a backgroundworker to run the method GetStatus(); every 200 milliseconds
private static BackgroundWorker _backgroundWorker;
internal static BackgroundWorker BackgroundWorker { get { return _backgroundWorker; } }
private void Initialize()
{
_backgroundWorker = new BackgroundWorker();
_backgroundWorker.WorkerSupportsCancellation = true;
_backgroundWorker.WorkerReportsProgress = true;
_backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundWorker_DoWork);
_backgroundWorker.RunWorkerAsync();
timer.Elapsed += new System.Timers.ElapsedEventHandler(OnElapsedTime);
timer.Enabled = true;
}
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (_backgroundWorker.CancellationPending)
{
e.Cancel = true;
return;
}
GetStatus();
Thread.Sleep(200);
}
|
|
|
|
|
It only runs once because you are only calling it once. What is you code for your OnElapsedTime event?
Also, why are you using Thread.Sleep in your DoWork event?
I may or may not be responsible for my own actions
|
|
|
|
|
I have used sleep because I want to call the Do_Work every 200ms
I am under the impression that the Do_Work event should get called every 200 ms but when debugging it seems that is not the case.
What should I do so that the DO_Work gets called every 200ms in a different thread?
Thanks
|
|
|
|