Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
My code :

string[] args = Environment.GetCommandLineArgs();
            int len = args.Length;
            if (len > 1)
            {
                string Path = args[len - 1];
                MessageBox.Show(Path);
            }


but the problem is the code well give me the path in the first time , after that for each time i try to get the path he will give me the first path.

how can i get the real path in every time?
Posted

1 solution

Instead of doing it that way, try this:

string[] args = Environment.GetCommandLineArgs();
foreach(string arg in args)
{
    MessageBox.Show(arg);
}


From you ============
thank you ,
but this code will give me the path of the .exe file

but my application is Single-Instance

http://www.codeproject.com/KB/cs/CSSIApp.asp[^]

what i want is when i open .txt file by "Open With" i want my application to give me the path of the .txt in each time i open .txt

My Response ==============

The reason you're seeing that is because your app is already open, and hasn't been shut down and restarted. You have to add some code where you're stopping a second instance from running.
 
Share this answer
 
v2
Comments
king_888 4-Oct-10 10:11am    
Thank you for your answer
But I think I did not explain the principle of the application work well
Example:
1. The user open .txt file , by "Open With" the application send the .txt file path to form2
2. After that form2 read the .txt file path (taken from form1)

Error:
if i have C:\01.txt and C:\02.txt
When we open the first file we will find that the path is correct , but when we open the second file we will find the path is incorrect becouse is the first file path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900