|
Thanks for your replys guys.
The xml file is generated automatically by some software we use and I want as little manual intervention as possible so I shall try the xml forum (which I hadn't actually noticed ).
Failing that I shall indeed try xpath to see whether it works.
Cheers
|
|
|
|
|
Hi Friends,
I googled the whole night and I browsed MSDN the entire day, but I did not find any results because what I wanted to know, maybe was termed as unneccasary or malfunctioning. Actually, I want to replicate my Console Program to a particular destination with the user's complete knowledge and permission. But the thing is that, I want to do that programmatically (i.e. not by exiting the program an then Copying or pasting it).
Like this:
Console.WriteLine("Are you sure to copy this program to C:\Program Files\? Press 'Y' for confirmation or 'N' to exit and hit enter");<br />
if (Console.ReadLine()=="Y")<br />
{<br />
}<br />
else if(Console.ReadLine()=="N")<br />
{<br />
return;<br />
}
Please help me. And also tell me if I am clear.
Cheers,
Rajdeep.NET
|
|
|
|
|
You may or maynot be able to actually do this, while the program is running.
Couple thoughts come to mind:
1). The normal means: File.Copy[^]
2). CreateProcess to a batch file that copies the .EXE from local to wherever
3). Save the state of your console app, create process to external program and terminate. External program copies app and then starts it back up, restore console app state.
That's "off the cuff" ...
|
|
|
|
|
|
I've just tried it on the exe for the solution I'm working on and it worked fine.
System.IO.File.Copy(
@"C:\Users\Dave\Documents\Visual Studio 10\Projects\TestSolution\TestSolution\bin\Debug\TestSolution.exe",
@"C:\Users\Dave\Documents\Visual Studio 10\Projects\TestSolution\TestSolution\bin\Debug\TestSolution2.exe"); Obviously you should check if the file exists already and you have write permissions on the folder.
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)
|
|
|
|
|
Hi Davey,
Thanks for replying! But the thing is that even if I assure this peice of code to my application, it would work fine for me but not in other's system (I mean client's machine). BTW not everyone gonna have Visual Studio installed and the file path will be different, ofcourse.
Like,
@"C:\Users\Dave\Documents\Visual Studio 10\Projects\TestSolution\TestSolution\bin\Debug\TestSolution.exe", will be the source file and @"C:\Users\Dave\Documents\Visual Studio 10\Projects\TestSolution\TestSolution\bin\Debug\TestSolution2.exe" is the destination where I'll be copying it. But, not any of my client are going to have the program installed in C:\Users\Dave\Documents\Visual Studio 10\Projects\TestSolution\TestSolution\bin\Debug\. Therefore, the program will be crash since it could not find the source to be copied.
Note: Is there some way like(Pseudo code) this:
System.IO.File.Copy("this.Executable", "destination");
where, 'this.executable' is the curent program, without defining its location (since the file path wont be same in every machine)
Please help me,
Cheers,
Rajdeep.NET
|
|
|
|
|
Rajdeep.NET wrote: But the thing is that even if I assure this peice of code to my application, it would work fine for me but not in other's system (I mean client's machine).
Yeah, so when the app launches under that user's ID, they better have the proper permissions to the next machine, or else the copy will fail.
|
|
|
|
|
string thisPath;
thisPath = System.Windows.Forms.Application.ExecutablePath;
thisPath = System.Reflection.Assembly.GetEntryAssembly().Location; then use thisPath as the source parameter for the Copy method.
BTW, you didn't mention that this was your problem in your original question. This[^] would have helped you solve this in a few seconds. You said you had searched before asking here - if that's true, then you need to read this[^]. I don't mean this in a condecending way, it's a very good article (94 '5 votes' can't be wrong).
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)
|
|
|
|
|
Hi Davey,
Yeah maybe I wasn't that describable in my question, but you got it correctly. Thanks! Now, I think that maybe I will need the Thread.Sleep method such that the program keeps running but with a certain interval in order to get the executable file path and then generating a batch file which will copy the executable to the destination directory. This is great. But ain't it a little difficult with .NET? I mean like, I have seen programs which replicate (termed as 'Malwares') but do they really use this type of complex programming logic for this purpose?
Cheers,
Rajdeep.NET!
|
|
|
|
|
I sincerely hope you're not writing anything 'nasty'. The path will not change while the program is running so this is a one time check, you can store the result in a static variable if needed.
Instead of sleeping, better to use a Timer and run the File.Copy when needed in a Tick or Elapsed event handler (depending on what type of Timer you use). If the Copy takes longer than the Interval of the Timer you will run into serious problems so set that property very carefuly and include some checking.
Why do you need to do this by the way? Before offering you any more help, I'd like to be sure of your intentions.
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)
|
|
|
|
|
Rajdeep.NET wrote: I googled the whole night and I browsed MSDN the entire day, but I did not find any results
You searched all day and night and couldn't find the File.Copy[^] method? Even when it is the FIRST result on google when you search for 'copy file c#'! (proof[^])
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Nothing like that, I did found File.Copy() method long days back. But this method can only be implemented whenever we know what file we are going to copy and to where. But maybe you have not been though by question properly. I want replication of my program right out of its execution.
Let me know if I need to be more clear,
Cheers,
Rajdeep.NET
|
|
|
|
|
Rajdeep.NET wrote: But this method can only be implemented whenever we know what file we are going to copy and to where.
Not true. All you have to ro is create the folder path you need.
|
|
|
|
|
It is easy to find out where the executing file is stored! System.Reflection.Assembly.GetExecutingAssembly().Location was one of the first results for it! You can then get the filename from that string and then use it in the destination string (eg. @"C:\Deistination\" + filename), it's really very simple, you're just making a big deal out of it.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Hi All,
In C#.net project, how to convert visio files (.vsd) to .pdf files.
Please guide me to achieve this functionality.
Thanks in advance..
|
|
|
|
|
NarVish,
As far as C# and VISIO are concerned, you'll want to investigate the Microsoft VSTO (Visual Studio Tools for Microsoft Office). That will get you your integration point, however, if VISIO does not support saving a document to PDF natively, you're most likely going to need to investigate purchasing a 3rd-party .NET component that can deliver that functionality for you.
My only other suggestion is to look on SourceForge.net for possible Open Source PDF projects.
|
|
|
|
|
Hi, I want to create an interface for a few applications that run with a command line interface (video codecs, to be specific). I've got it sort of working but after I run one application with it, it just stops displaying the output.
Code on the "Run App" Button: (pro_App is the name of my process component)
pro_App.StartInfo.FileName = txt_App.Text;
pro_App.StartInfo.Arguments = txt_Args.Text;
pro_App.Start();
pro_App.BeginOutputReadLine();
but_Run.Enabled = false;
Events:
private void pro_App_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
rtx_Display.AppendText(Prefix + e.Data);
Prefix = Environment.NewLine;
}
}
private void pro_App_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
rtx_Display.AppendText(Prefix + "Error: " + e.Data);
Prefix = Environment.NewLine;
}
}
private void pro_App_Exited(object sender, EventArgs e)
{
but_Run.Enabled = true;
rtx_Display.AppendText(Prefix + "<Application Finished>";
Prefix = Environment.NewLine;
pro_App.CancelOutputRead();
}
Component Properties:
this.pro_ShellApp.EnableRaisingEvents = true;
this.pro_App.StartInfo.CreateNoWindow = true;
this.pro_App.StartInfo.Domain = "";
this.pro_App.StartInfo.ErrorDialog = true;
this.pro_App.StartInfo.LoadUserProfile = false;
this.pro_App.StartInfo.Password = null;
this.pro_App.StartInfo.RedirectStandardError = true;
this.pro_App.StartInfo.RedirectStandardOutput = true;
this.pro_App.StartInfo.StandardErrorEncoding = null;
this.pro_App.StartInfo.StandardOutputEncoding = null;
this.pro_App.StartInfo.UserName = "";
this.pro_App.StartInfo.UseShellExecute = false;
this.pro_App.SynchronizingObject = this
Any ideas? Thanks.
|
|
|
|
|
Hi,
I have never done it like that, I tend to use explicit threads for reading stdout and stderr.
The one thing I noticed is you don't have a pro_App.CancelErrorRead();
BTW: you do have try-catch showing the full Exception.ToString() do you?
Hope that helps.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for your reply, how would I go about doing it your way? I haven't been using C# for very long so I've been relying mostly on tutorials and the MSDN documentation to find out how to do something new.
I do call pro_App.CancelErrorRead(); in the _Exited event to terminate the async reading but should I have it somewhere else too?
And I don't get an exception when trying to run the second app, it runs fine but just doesn't display any of the output.
|
|
|
|
|
Hi,
the code shown only included CancelOutputRead(); and no CancelErrorRead();
I tend to explicitly create a thread for reading stdout using a synchronous read in a while loop; similar for stderr. While the original thread waits for process exit (using a busy wait, i.e. a loop including a sleep(300)), waits one more second, then forces the other threads to terminate (gracefully if possible).
I started doing so back on Win98 where .NET 1.0 and 1.1 had some problems dealing with those externals streams, not sure it still is necessary nowadays.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi,
another thought:
AFAIK the DataReceived events get executed on another thread, so they shouldn't (probably can't) access GUI Controls. The only correct way to cope with that is by using delegates (see Control.InvokeRequired/Control.Invoke). I hope you didn't use the Control.CheckForIllegalCrossThreadCalls=false; monstrosity since that is a sure way for failure.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Hi,
is it still not working when you have BOTH CancelRead calls present?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Nope it's still not working. The application still gets executed but it stops displaying the output after running the first app.
|
|
|
|
|
Hi,
neoflame wrote: this.pro_ShellApp.EnableRaisingEvents = true;
just noticed a possible confusion between pro_ShellApp and pro_App.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|