executing a program by double clicking on a file shown in list view ( C# )
-
Hey people I´m still having a little problem here!!! I´m trying to execute a program by double clicking on a file shown in List View... The methods to show fthe files and folder I did and it´s working well... to execute a file I created a new mwthod
executeFile
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}as you can see
getFullPath(nodeCurrent.FullPath)
gets the path for the directory where the file is. I don´t know if I did right but do call the method I greated another by doubleclickin on th list viewlvFiles_SelectedIndexChanged
and called the methodexecuteFile(nodeCurrent)
but It doesn´t work... it says nodeCurrent doesn´t exists on the namespace... I don´t know if I didexecuteFile
right... Could some good soul please help me???? Thanks! -
Hey people I´m still having a little problem here!!! I´m trying to execute a program by double clicking on a file shown in List View... The methods to show fthe files and folder I did and it´s working well... to execute a file I created a new mwthod
executeFile
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}as you can see
getFullPath(nodeCurrent.FullPath)
gets the path for the directory where the file is. I don´t know if I did right but do call the method I greated another by doubleclickin on th list viewlvFiles_SelectedIndexChanged
and called the methodexecuteFile(nodeCurrent)
but It doesn´t work... it says nodeCurrent doesn´t exists on the namespace... I don´t know if I didexecuteFile
right... Could some good soul please help me???? Thanks! -
Hi, don't know if I understand everything. Does the compiler say "Namespace doesn't exists" or does this error occur during runtime? Could you please post a bit more code, like the "lvFiles_SelectedIndexChanged" method? Sebastian
Hi Sebastian! The compiler says! Well the method just call execute file!!! Nothing more!
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}private void lvFiles\_SelectedIndexChanged(object sender, System.EventArgs e) { executeFile(nodeCurrent); }
I tried to use shell dll too! But a little bit lost with it.... I know that I maybe doing something wrong but... I´m more familiar with structured C.
-
Hi, don't know if I understand everything. Does the compiler say "Namespace doesn't exists" or does this error occur during runtime? Could you please post a bit more code, like the "lvFiles_SelectedIndexChanged" method? Sebastian
Hi Sebastian I just tried another method that is ALMOST working!! Just a tiny detail that it open the program by doubleclicking the file BUT it doesn´t open the file itself!!!
private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
{
ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
shellExecute.Path = @"C:\Arquivos de programas\AutoCAD 2008\acad.exe";
shellExecute.Execute();
}just a simple shell dll command! Now I need to open the file itself!!! Any clue??? tnx!
-
Hi Sebastian! The compiler says! Well the method just call execute file!!! Nothing more!
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}private void lvFiles\_SelectedIndexChanged(object sender, System.EventArgs e) { executeFile(nodeCurrent); }
I tried to use shell dll too! But a little bit lost with it.... I know that I maybe doing something wrong but... I´m more familiar with structured C.
Well, where is nodeCurrent declared for lvFiles_SelectedIndexChanged? That's why the compiler says that there is no nodeCurrent... You have to get it the current selected item from your listview. Something like:
// this is your selected item
lvFiles.SelectedItems[0]By the way, are you using a TreeView or a ListView control? Regards Sebastian
-
Hi Sebastian! The compiler says! Well the method just call execute file!!! Nothing more!
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}private void lvFiles\_SelectedIndexChanged(object sender, System.EventArgs e) { executeFile(nodeCurrent); }
I tried to use shell dll too! But a little bit lost with it.... I know that I maybe doing something wrong but... I´m more familiar with structured C.
First, it's not good practice to pass a TreeNode object to a method called "executeFile". It's kind of counter-intuitive. You should be passing in a string decribing the full path to a file. "executeFile" shouldn't need an entire TreeNode to do it's job. Now, what does
getFullPath
return when you pass in a TreeNode??A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Well, where is nodeCurrent declared for lvFiles_SelectedIndexChanged? That's why the compiler says that there is no nodeCurrent... You have to get it the current selected item from your listview. Something like:
// this is your selected item
lvFiles.SelectedItems[0]By the way, are you using a TreeView or a ListView control? Regards Sebastian
It´s using both!!!! But treeView shows only folders ald list view only files!! I liked this way because it keeps wiewing more organized! I tried another method BUT I´m also trying this nodeCurrent is used to popuate lvFiles with files... it gets the current node and shows files. getFullPath gets the path from the root to the current node... I tried shell too you might see it because it almost worked.. just for the detail that it opns the program but not the file (I know that I´m missing a line or some statement) I´m lost because it´s my first c# experience!!!!
-
First, it's not good practice to pass a TreeNode object to a method called "executeFile". It's kind of counter-intuitive. You should be passing in a string decribing the full path to a file. "executeFile" shouldn't need an entire TreeNode to do it's job. Now, what does
getFullPath
return when you pass in a TreeNode??A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Hello Dave!!! getFullPath returns the path from the root to the current node! Yeah it makes sense to me now!!! It´s totally silly to pass something that is pointing to a directory to execute a file.... It doesn´t needs to know WHERE THE FIE IS because it is already showing me the files! I´m beginning to understand!
-
Hey people I´m still having a little problem here!!! I´m trying to execute a program by double clicking on a file shown in List View... The methods to show fthe files and folder I did and it´s working well... to execute a file I created a new mwthod
executeFile
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}as you can see
getFullPath(nodeCurrent.FullPath)
gets the path for the directory where the file is. I don´t know if I did right but do call the method I greated another by doubleclickin on th list viewlvFiles_SelectedIndexChanged
and called the methodexecuteFile(nodeCurrent)
but It doesn´t work... it says nodeCurrent doesn´t exists on the namespace... I don´t know if I didexecuteFile
right... Could some good soul please help me???? Thanks!Hello folks! I´m almost reaching what I wanted to do! Now It does open the file... BUT JUST that file specified in the path on the code as you will see right down!
private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
{
ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
shellExecute.Path = @"F:\Painel de Controle ETECH\Projetos ETECH\Acessórios\80010005.dwg";
shellExecute.Execute();
}It will open ONLY 80010005.dwg "Projetos ETECH" is the root node (folder) and contains a lot of childs (subfolders of especific projects) wich contains CAD drawings (thousands millions of DWGs). I need a way to get the path of any selected file. What I thought was to create a method that gets the path where you are and the name of the file you selected (string) and put them together to for the path to te file to be executed... Am I in the right way or there is something easier???? Best Regards for all you!!!!
-
Hello folks! I´m almost reaching what I wanted to do! Now It does open the file... BUT JUST that file specified in the path on the code as you will see right down!
private void lvFiles_SelectedIndexChanged(object sender, System.EventArgs e)
{
ShellLib.ShellExecute shellExecute = new ShellLib.ShellExecute();
shellExecute.Verb = ShellLib.ShellExecute.OpenFile;
shellExecute.Path = @"F:\Painel de Controle ETECH\Projetos ETECH\Acessórios\80010005.dwg";
shellExecute.Execute();
}It will open ONLY 80010005.dwg "Projetos ETECH" is the root node (folder) and contains a lot of childs (subfolders of especific projects) wich contains CAD drawings (thousands millions of DWGs). I need a way to get the path of any selected file. What I thought was to create a method that gets the path where you are and the name of the file you selected (string) and put them together to for the path to te file to be executed... Am I in the right way or there is something easier???? Best Regards for all you!!!!
Hi, it's me again. Sry, for didn't answering yesterday, was on my way home. Okay, so opening the file is not the problem. The problem is to get the path and name of the file to open. So let me guess that you doing something like this.
public string getFullPath(string sPath) {
string sFileName = lvFiles.SelectedItem[0].Text;
return System.IO.Path.Combine(sPath, sFileName);
}private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}If you are doing this, you get an error from the compiler? Did you include the Namespace (using System.Windows.Forms)? Or rewrite it to
private void executeFile(System.Windows.Forms.TreeNode nodeCurrent) {
...
}Does this solve your problem? Regards Sebastian