Shell Programming - Loading a file selected on list view component
-
Dave, I tried but the namespace doesn´t exists.... I´m using VisualStudio 2003!!! I think I can´t avoid shell....
modified on Friday, October 10, 2008 11:13 AM
Yes, it does exists, and has since .NET 1.0. What does your code look like??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hello folks!!! I have a serious problem. I´making a "file explorer" in C# and it has to set a root node from an external HDD and show only files and folders hierarchically down it. This I´ve done and it´s working "fine"... with some problems but working! The major problem is that I´ve to load a file by double clicking it on the list view (DWGs MUST open with AutoCAD, DOCs and Spreadsheets MUST open with MS Ofiice, Pictures must open with paint and whatever!) I know that I need to use ShellAPI BUT I´m having problems to use it properlly... I´ve been reading some HotTo´s, articles, walkthroughs (including C# does Shell) but none answer my question especifically..... Can some one please help me? I´m desperate!!!! thanks PS. I´m using framework 1.1/2.0 with .NET 2003
I´ll try to explain my code while my poor English let :P!! It´s a file manager (a TreeView and a ListView). The Tree View shows only FOLDERS and List View only FILES. A file manager similar to Windows explorer but with a RootNode set to an especific folder on an external HD. Only the Root node and subnodes are visible. This I´ve done but not working properlly... just working... The problem I´m having is to load the program by double-clicking on the file in the ListView. The code is shown down
using System;
using System.Drawing;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Management;
using System.Globalization;namespace Painel_de_Controle_ETECH
{
public class Workspace : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView tvFolders;
private System.Windows.Forms.ImageList m_imageListTreeView;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ListView lvFiles;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.IContainer components;public Workspace() { InitializeComponent(); //Metodo para preencher a tvFolder PopulateDriveList(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Workspace)); this.tvFolders = new System.Windows.Forms.TreeView(); this.m\_imageListTreeView = new System.Windows.Forms.ImageList(this.components); this.toolBar1 = new System.Windows.Forms.ToolBar(); this.splitter1 = new System.Windows.Forms.Splitter(); this.lvFiles = new System.Windows.Forms.ListView(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // tvFolders // this.tvFolders.Dock = System.Windows.Forms.DockStyle.Lef
-
I´ll try to explain my code while my poor English let :P!! It´s a file manager (a TreeView and a ListView). The Tree View shows only FOLDERS and List View only FILES. A file manager similar to Windows explorer but with a RootNode set to an especific folder on an external HD. Only the Root node and subnodes are visible. This I´ve done but not working properlly... just working... The problem I´m having is to load the program by double-clicking on the file in the ListView. The code is shown down
using System;
using System.Drawing;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Management;
using System.Globalization;namespace Painel_de_Controle_ETECH
{
public class Workspace : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView tvFolders;
private System.Windows.Forms.ImageList m_imageListTreeView;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ListView lvFiles;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.IContainer components;public Workspace() { InitializeComponent(); //Metodo para preencher a tvFolder PopulateDriveList(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Workspace)); this.tvFolders = new System.Windows.Forms.TreeView(); this.m\_imageListTreeView = new System.Windows.Forms.ImageList(this.components); this.toolBar1 = new System.Windows.Forms.ToolBar(); this.splitter1 = new System.Windows.Forms.Splitter(); this.lvFiles = new System.Windows.Forms.ListView(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // tvFolders // this.tvFolders.Dock = System.Windows.Forms.DockStyle.Lef
NOT THE WHILE BLOODY THING!! Just the part where you're having the problem launching files! Thankfully, that part is at the end of the file. Noone is going to go looking through all that code for a small part... Your
executeFile
method just needs to do something like:Process.Start(_filepath_)
Because the Shell interpret spaces as a delimiter, it's a good idea to enclose filepaths in double quotes.
Process.Start(String.Format("\\"{0}\\"", filepath))
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
NOT THE WHILE BLOODY THING!! Just the part where you're having the problem launching files! Thankfully, that part is at the end of the file. Noone is going to go looking through all that code for a small part... Your
executeFile
method just needs to do something like:Process.Start(_filepath_)
Because the Shell interpret spaces as a delimiter, it's a good idea to enclose filepaths in double quotes.
Process.Start(String.Format("\\"{0}\\"", filepath))
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008hahahahahaha sorry for that, my mistake :)!!!! It was just if you wanted to to test it!!! So I showed the whole thing!!!! Well, as you can see I´m bloody new on c# and .net!!! The other question is where I call the executeFile method??? but the complier is still yelling me that System.Diagnosics.Process namespace doesn´t exists!!! There is something else I should do? Thanks!!! I really appreciate the whole support you are giving me!!!
-
hahahahahaha sorry for that, my mistake :)!!!! It was just if you wanted to to test it!!! So I showed the whole thing!!!! Well, as you can see I´m bloody new on c# and .net!!! The other question is where I call the executeFile method??? but the complier is still yelling me that System.Diagnosics.Process namespace doesn´t exists!!! There is something else I should do? Thanks!!! I really appreciate the whole support you are giving me!!!
Oops - that might be because of a typo in my earlier post! Diagnosics should be Diagnostics (missed the 't') :-O
Dave
BTW, 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) -
Oops - that might be because of a typo in my earlier post! Diagnosics should be Diagnostics (missed the 't') :-O
Dave
BTW, 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)hehehehehehehe no problem dude!!!! just one last question... on the header of the code a put just
using System.Diagnostics;
??? because System.Diagnostic.Process is unrecognized too : / :) Thank you dudes.. I really owe you one!!!!
-
hehehehehehehe no problem dude!!!! just one last question... on the header of the code a put just
using System.Diagnostics;
??? because System.Diagnostic.Process is unrecognized too : / :) Thank you dudes.. I really owe you one!!!!
In 'using's at the top of your file you can only put namespaces. Process is a class within System.Diagnostics so it can't be put in the using (and of course Start is a method of that class). For future reference, typos like that happen quite regularly. If something's not found there's several ways to find the error. 1. Type the line letter by letter until intellisense kicks in, and see if what you need is in the list (spelled correctly!). 2. Use the Object Browser and search for the class and/or method, or alternatively, browse from the base namespace. This can be good for finding out if there are any references you need to add to your project too. 3. Paste it into google, if there is a typo, at the top of the first page of search results there will normally be a suggested correct spelling. The first two have the added benifit of showing you all the other stuff in that namespace/class that you wouldn't have known about otherwise. You can learn loads of new stuff by browsing around in there.
Dave
BTW, 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) -
hehehehehehehe no problem dude!!!! just one last question... on the header of the code a put just
using System.Diagnostics;
??? because System.Diagnostic.Process is unrecognized too : / :) Thank you dudes.. I really owe you one!!!!
Then you just use Process, not System.Diagnostics.Process. The
using
statement at the top frees you from haing to type the entire qualifier. As for where you call the execute statement, that's up to your design! Though, having looked at the entire code you posted, you don't have any code doing anything with the files in the listview after the listview is populated. So, I have no idea what you expect the user to do to launch a file. What happens there is totally up to you.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Then you just use Process, not System.Diagnostics.Process. The
using
statement at the top frees you from haing to type the entire qualifier. As for where you call the execute statement, that's up to your design! Though, having looked at the entire code you posted, you don't have any code doing anything with the files in the listview after the listview is populated. So, I have no idea what you expect the user to do to launch a file. What happens there is totally up to you.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Yeah! That´s where I´m placing the method executeFile. I´ll call by an event like listView_Click or eiter the listView_SelectedIndex The code to populate I found here at CP and with a few changes I made it point to an expecific folder to be the root (just basic programming and basic O.O. concepts). My professors at college helped me a little because they are not quite familiar with .NET Framework. Even I got more familiarity with Assemble Languages and Structured C/Pascal... and few notions of O.O C++ and Objective C(Mac) (I HATE JAVA). I´m still junior in .NET but I´m trying!!!! I almost did it... just a few errors!!! I appreciate all the help!!! I owe you guys a beer!!!! Thanks
-
Yeah! That´s where I´m placing the method executeFile. I´ll call by an event like listView_Click or eiter the listView_SelectedIndex The code to populate I found here at CP and with a few changes I made it point to an expecific folder to be the root (just basic programming and basic O.O. concepts). My professors at college helped me a little because they are not quite familiar with .NET Framework. Even I got more familiarity with Assemble Languages and Structured C/Pascal... and few notions of O.O C++ and Objective C(Mac) (I HATE JAVA). I´m still junior in .NET but I´m trying!!!! I almost did it... just a few errors!!! I appreciate all the help!!! I owe you guys a beer!!!! Thanks
Having one on you right now :beer: :-D
Dave
BTW, 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)