Connecting Tech Pros Worldwide Help | Site Map

how to pass arguments from a c# console applucation to a windows forms application

Newbie
 
Join Date: Nov 2009
Posts: 1
#1: 2 Weeks Ago
i am trying to call a windows forms application form a console application in which the text box has to be defaultly populated with the path i am passing
Thanks in advance
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#2: 2 Weeks Ago

re: how to pass arguments from a c# console applucation to a windows forms application


A quick Google for "C# pass arguments between applications"
Found me this, as well as other tips.

Quote:
Expand|Select|Wrap|Line Numbers
  1. System.Diagnostics.ProcessStartInfo otherApp = new System.Diagnostics.ProcessStartInfo("file.exe");
  2.  
  3. otherApp.Arguments = "args here";
  4.  
  5. Process.Start(otherApp);


in the Arguments property, insert there the arguments you want to give your other application. It will then recieve it and if its your own application you can either modify the main() method of it to accept the string[] arguments/parameters:

Expand|Select|Wrap|Line Numbers
  1. static void Main(string[] args)
  2.         {
  3.  
  4.             if (args.Length > 0)
  5.             {
  6.                 Console.Write("args length: " + args.Length.ToString());
  7.                 Console.Write("\n\n");
  8.                 foreach (string curArg in args)
  9.                 {
  10.                     Console.WriteLine(curArg);
  11.                 }
  12.             }
  13.             else
  14.             {
  15.                 Console.WriteLine("No args supplied");
  16.             }
  17.  
  18.         }


as an example. Or you can use the Environment.GetCommandLineArgs(); which returns a string[] array of arguments given to the application.
Please let us know if this helped you.
Reply