|
Yes that's right, foreach or just a plain for loop.
string[] machineNames = System.IO.File.ReadAllLines(filename);
foreach (string name in machineNames) {
DoTask(name);
}
for (int i = 0; i < machineNames.Length; i++) {
DoTask(machineNames[i]);
}
Alan.
|
|
|
|
|
AH thank you so much. Ill give this ago.
-Ryan
|
|
|
|
|
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Load machines to search";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(fdlg.FileName, FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(fs);
the code above opens the dialog and im able to choose my txt file but how do i read the data to pip it all into the string
string[] machineNames = System.IO.File.ReadAllLines(filename);
foreach (string name in machineNames) {
DoTask(name);
}
thank you for your time and help.
|
|
|
|
|
Hey, what's MSDN for then! As I'm feeling generous, I'll give you a brief explanation anyway.
File.ReadAllLines is a convenience method that the framework supplies. It does the lot, that is, open the file, create a string array, read the lines into the array and then close the file. All you need to do is pass in the name of the selected file from the OpenFileDialog.
There are several other methods of this type that are useful when working with files that aren't too large. They are all in the System.IO.File class.... and that neatly brings me back to MSDN if you need to know any more.
Alan.
|
|
|
|
|
I am able to get them to load now to the listview but my question is once i have them loaded in the listview under machine colum i want to hit search and can the loop go through each listvew item perform the tast i want then on under status colum say file deleted if found if not file not found. then move on to the next mahine name untill the end. Check out the link below to see what im talking about.
www.summeylabs.com/images/prog.jpg
Thank you again for all your help.
|
|
|
|
|
Hi,
I think you might be better off deferring adding data to the listview until results arrive from the networked computers.
I'm guessing that your program already has code to handle one host name taken from the Host textbox, probably in the Search button click handler, and it should be possible to reuse that code. We refactor the code in the click handler like this:
private void SearchBtn_Click(object sender, EventArgs e) {
DoTask(HostTextBox.Text);
}
The DoTask method contains all the functionality to query and process the results from ONE networked machine. The advantage of refactoring is that you can now call the DoTask method for each host name in the list, code which could be placed into a menu click handler.
private void OpenFileMenuItem_Click(object sender, EventArgs e) {
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Load machines to search";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK) {
string[] machineNames = System.IO.File.ReadAllLines(fdlg.FileName);
foreach (string hostname in machineNames) {
DoTask(hostname);
Application.DoEvents();
}
}
}
Now your program can handle a list of hosts, by reading a file, and it can still take a single name from the textbox.
The user interface (UI) can freeze during list processing because the loop prevents any UI updates until iteration has completed. The correct way to keep a UI active is to execute long duration tasks in a secondary thread, but to do that is another level of complexity which I don't think you're ready for just yet. I've inserted a call to Application.DoEvents() into the loop which is the poor man's way of keeping the UI responsive. In simple terms this allows keyboard or mouse input to be read, and the application windows to be redrawn on every iteration. Without it the UI would not update until the loop had ended.
Alan.
|
|
|
|
|
I'm trying to write a XmlDocument like so:
<br />
XmlDocument doc = new XmlDocument();<br />
<br />
<br />
StreamWriter s = new StreamWriter("output.xml");<br />
<br />
XmlTextWriter w = new XmlTextWriter(s);<br />
<br />
<br />
doc.WriteContentTo (w);<br />
<br />
w.Flush();<br />
<br />
s.Flush();<br />
s.WriteLine();<br />
s.Close();<br />
But it writes all the xml on one line. How do I make it put each node on its own line?
|
|
|
|
|
Could try the Formatting property of the XmlTextWriter.
|
|
|
|
|
|
|
Hi,
I've a list view which has got 5 columns some time i'll get fill only one column and 1 row, by that time remaining columns are highlighted with square (basically selected) I want to avoid that, any chance to restrict users to select or disable one particular row in list view?
|
|
|
|
|
can i call button_click event from code
pictureclick_event()
{
//from here i want to call button clcik event with out clicking button
}
buttonclick_event()
{
}
This code was posted by me...
|
|
|
|
|
Call the button's PerformClick() method
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
tnx
m doin device application in .net
how to close a form and navigate to another form
this.close and dispose is not working
This code was posted by me...
|
|
|
|
|
Vivek Vijayan wrote: how to close a form and navigate to another form
Hi,
This code should do it:
this.Hide();
Form NewForm = new NewForm();
NewForm.ShowDialog();
I hope this helps.
|
|
|
|
|
Technically, yes, because an event handler is just a function like any other.
But - it may be better in these cases to separate out the code that would be called by multiple event handlers into its own function. Something like this:
void MyCommonFunction()
{
...
}
void PictureClick_Event(o as object, e as EventArgs)
{
MyCommonFunction();
}
void ButtonClick_Event(o as object, e as EventArgs)
{
MyCommonFunction();
}
|
|
|
|
|
|
Hi,
I think I understand your question. What you're looking for is this:
pictureclick_event()
{
MySexyButton.PerformClick();
}
// The above code will perform a Click on the button without you having to actually click it. Pretty sweet huh?
I hope this helps.
If you liked the answer I have provided, then please click the 'Good Answer' link on the bottom-right of my post.
|
|
|
|
|
How to fill a dataset using two tables coz i want to use that dataset for crystal report.
|
|
|
|
|
DataTable table1 = new DataTable();
DataTable table2 = new DataTable();
DataSet dataSet = new DataSet();
dataSet.Tables.Add(table1);
dataSet.Tables.Add(table2);
|
|
|
|
|
the code is like this..
SqlCommand cmd;
SqlConnection conn;
SqlDataAdapter sda;
conn = new SqlConnection("server=Sai2; database=Inventory; uid=sa; pwd=123456;");
cmd = conn.CreateCommand();
cmd.CommandText = "select * from stock";
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataS.Stock ds = new SisInventorySystem.DataS.Stock();
sda.Fill(ds, "stock");
Crystal_Reports.TotalStockRpt TtlStkRpt = new SisInventorySystem.Crystal_Reports.TotalStockRpt();
TtlStkRpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = TtlStkRpt;
crystalReportViewer1.DisplayToolbar = true;
Now i have to run one more Query "select * from Company" having nothing in common between table company and stock.
|
|
|
|
|
You can write a stored procedure that returns multiple recordset and get the resultset directly mapped with a dataset, it will create the same number of datatables in your dataset as the count of resultset in your procedure...
|
|
|
|
|
DataAdapter.Fill perhaps? If you're using SQL Server for your database, you can call a stored procedure that returns two result sets - each will be filled in the dataset as a separate DataTable. The stored procedure is simple:
CREATE PROCEDURE Sample
AS
BEGIN
select * from table1;
select * from table2;
END
|
|
|
|
|
ok...
and after what to write...
da.fill(ds,"whichtable");
can i write the both table....
|
|
|
|
|
Access the tables through the DataSet's Tables collection:
DataTable dt0 = ds.Tables[0];
DataTable dt1 = ds.Tables[1];
|
|
|
|