In Form1 i did this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace test
{
public partial class Form1 : Form
{
WindowsFormsApplication1.Form1 f1;
public Form1()
{
InitializeComponent();
MessageBox.Show("Oops something went wrong sorry");
f1 = new WindowsFormsApplication1.Form1();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Where f1 is the second project i just added.
Now i added the seocnd project as a reference.
In the second project i did:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string[] hardDrivedInfo;
string applicationFileName;
public Form1()
{
InitializeComponent();
applicationFileName = Path.GetDirectoryName(Application.ExecutablePath);
But the applicatioFileName show me the path of the exe file of the first project while i need to get the directory + file name of the second project wich is in directory: D:\C-Sharp\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
The directory of the first project is: D:\C-Sharp\test\test\test\bin\Debug\test.exe
But i need to make that applicationFileName will show: D:\C-Sharp\test\test\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
EDIT **
What i want to do is to run the first main project then after the messagebox is popup and i close it it will run the second project will copy the second project exe file to another location like D: and will run the exe file of the second project. So if i delete the first project exe file the second one on D: will keep running.
Your text is a bit unclear, but I’m guessing you’re trying to get the name of the referenced assembly, rather than the one that started the process, right?
Try using
Assembly.GetExecutingAssembly(). Then you can get the full path from theLocationproperty.