|
What if u use the process to get the name of the machine ................... like
<br />
using System.Diagnostics;<br />
Process p=new Process();<br />
String name=p.MachineName;<br />
<br />
then use a database to write to it
|
|
|
|
|
I already know my machine names, i have them all in a machine.txt like this
lap-0101
lap-0102
ash-production
thats just 3 machines i have for testing ill have like 80. Think of it like this its like loading a password file into a password cracking prog.
it reads it line by line so for instance you would click open choose machine.txt then after it loads them all maybe a message box says all names loaded start search ok or cancle then click ok then it gos out to each machine deletes the file i have specified in my code and reports back in the listview all this works now if i manually type in the machine name into the text box if you look at this link you will see my application
www.summeylabs.com/images/authplay.jpg
but i am trying to automate the tast by supplying a file with all the names in it already.
i just dont know how to load each name one line at a time make do somthing else then once its done do it all over again untill end of file.
|
|
|
|
|
Hi,
Your question finally seems to have been resolved as how do I read the file. Is that correct? The following code would get the lines from the text file in a string array.
string[] machineNames = System.IO.File.ReadAllLines(filename);
After that it would be a simple matter to iterate through the individual names and perform a task with each one.
Alan.
|
|
|
|
|
I would use a for each statement to iterate through the individual names?
Thank you for your help
|
|
|
|
|
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.
|
|
|
|