|
StreamReader sr = new StreamReader(fileName);
StreamWriter sw = new StreamWriter(fileName);
|
|
|
|
|
Thanks for your quick reply.
To open in a program, we use readers and writers.
But I would like open a file as like we open a file by double-click in system folders.
I have list of file paths in listview.
when I select those, corresponding files should get open.
Please guide me to achieve this.
|
|
|
|
|
System.Diagnostics.Process.Start(filename);
|
|
|
|
|
Use <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx">Process.Start</a>[<a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx" target="_blank" title="New Window">^</a>] .
Enjoy
I are troll
|
|
|
|
|
See Process.Start(fileName) - that'll do 'er.
You beat me too it!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced
|
|
|
|
|
Thank you all for your support.
Its working
|
|
|
|
|
Hi all,
I want to store some files in a database. So it would be nice to keep all information (fileinfos, attributs and rights)
when they will be restored.
Is there a way to get all the (file)informations on block (struct) and not to collect them by each item with
FileInfo or FileAttributes.
And the next question is how to restore these fileinfos in an similar, easy way ?
tnx
frank
|
|
|
|
|
Hi,
I am executing the batch file with Process.Start(); I want to show the progress bar to the user. As it take so much time, so the user should get that its working, otherwise it seems to be hanged out.
(Note: Currently I m showing status label as process is running, but its not look good.)
Please advise me for the same.
My mail id: nitin.jenekar@gmail.com
modified on Thursday, April 23, 2009 7:49 AM
|
|
|
|
|
We don't respond by email here. Any replies are posted to the forum for the benifit of others.
Just add a progress bar to your form. If you want your UI to remain responsive you can hook it up to a background worker like I've done here[^].
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)
|
|
|
|
|
But batch file and windows form's progess bar/ marquee are two different process. How to run both simultaneously. As when batch process gets started, it freezes other processes.
Regards,
Nitin Jenekar
|
|
|
|
|
Start the batch file in the DoWork event handler
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)
|
|
|
|
|
Its not as easy to implement for me. Please guide me more.
As I have tried to execute the batch file from DoWork, its not doing whatever is desired.
My batch process runs for minimum 20-30 min.
On button click, I am runnnig following code.
Please let me know how to execute the progress bar in parallel to this.
string filePath = txtPath.Text + "\\UploadTemplates.bat";
Process proc = new Process();
proc.StartInfo.FileName = filePath;
proc.StartInfo.WorkingDirectory = txtbinPath.Text;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
// Start the process
string startTime = DateTime.Now.ToString();
proc.Start();
// Attach the output for reading
StreamReader sOut = proc.StandardOutput;
// Close the process
proc.Close();
// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
//sOut.Close();
string endTime = DateTime.Now.ToString();
sw = File.CreateText(txtbinPath.Text + "\\UploadResult.txt");
sw.WriteLine("Process started at :" + startTime);
sw.WriteLine(results);
sw.WriteLine("Process completed at :" + endTime);
sw.Close();
|
|
|
|
|
Personally I don't think there's an acceptable solution to doing that. Progress bars tell you how far through an operation you are. How do we know? It depends on how large your batch file is and where you are through it. How do you know that?
Although you could kludge something together personally I would bother. Just use some sort of animated gif or something to give the user the idea that something is happening and will one day complete.
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: Personally I don't think there's an acceptable solution to doing that. Progress bars tell you how far through an operation you are. How do we know?
Have you used progressbars before? Doing a quick count of the number of Lines in your file and then passing that to the progressbar.Maximum gives you the number of lines you are processing.
<br />
string line = sr.ReadLine();<br />
while (line != null)<br />
{<br />
line = sr.ReadLine();<br />
lineCount++;<br />
}<br />
sr.Close();<br />
lineTot = lineCount;<br />
Once you have the total number of lines you can pass that through to the ProgressBar.Maximum.
<br />
progressBar1.Minimum = 0;<br />
progressBar1.Maximum = lineTot;<br />
Your answer seem to indicate that it is impossible to do and not worth it. I have implimented this in about less than 10 lines of code.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
But the OP isn't reading lines from a file -- instead, they are running an external process (a batch file), which is quite different.
|
|
|
|
|
Yeah, thanks for that invaluable info. So now you've set the minimum and maximum how are you going to update the control as a batch file in a seperate process executes exactly?
Regards,
Rob Philpott.
|
|
|
|
|
Exactly the same what I like to say. As its a different process, when the batch file execution get starts, it freezes all other process.
I have tried BackgroundWorker, but its not working in case of a batch file. It works for other simple processes.
Some one suggested to use Thread pool for this, I am trying with it.
|
|
|
|
|
What does your batch job do? Do you have some sample code to look at? It is probably best to use Threading.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
A progress bar should show progress, so the first thing to do is answer the question: how do you measure and quantify progress? what is going to provide this information?
it depends on the action(s) going on, of which you told us nothing.
|
|
|
|
|
Not a compulsion to use a progress bar, I could use Marquee instead of it. My only moto is to show something is running, to know the user that the system has not stopped working.
|
|
|
|
|
As far as I can see from the previous replies, the only valid way to use a ProgressBar would be to set its style to ProgressBarStyle.Marquee . This would indicate that something is happening, without the requirement to measure progress.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ya,Thanks. I am satisfied with you. I dont have any problem for using marquee, but the question is how to implement this?
|
|
|
|
|
Add the ProgressBar to the Form , or a StatusProgressBar to the StatusBar , then in the Properties Window set the Style property to Marquee . The marquee effect should start right away, in the designer. So to turn it on and off at the right times change the Style property, in your code. To marquee to start it, and to block (and set value = maximum) to stop it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks, But I dont have any problem in using Marquee. I know how to implement marquee, also with the help of toolStripProgressBar.
But the concern is, execution of a batch file is a diferent process, which will freezes other processes, like progressbar or toolStripProgressBar. Please guide me for that, if u can.
|
|
|
|
|
Ah, now I understand.
I'm afraid that I don't have a solution for that. I hope someone else is able to help you though.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|