Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension
Finding path/filename associated with extension Finding path/filename associated with extension
Finding path/filename associated with extension
Go Back  Xtreme Visual Basic Talk > > > Finding path/filename associated with extension


Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2011, 09:23 AM
stokeentertainm's Avatar
stokeentertainm stokeentertainm is offline
Contributor
 
Join Date: Jan 2005
Location: Stoke-on-Trent, UK
Posts: 439
Default Finding path/filename associated with extension


Hi all,

I suppose technically this isn't .NET specific but I suspect this is something to do with the registry and I'm using .NET!

I'm trying to find out how to get the fully qualified path relating to a file type. For example, the system knows that to open a PDF file it needs to launch C:\Program Files\Adobe\Adobe Reader 10.0\Reader\acrord32.exe

I've had a good long search through the registry and found a lot of references to the adobe path - probably too many - and I've edited them to try and "break" the process so I can identify which one is used to discover the path but with no luck. I'm assuming this has something to do with HKEY_CLASSES_ROOT?

Any clues?

Thanks,
Reply With Quote
  #2  
Old 06-24-2011, 03:13 PM
snarfblam's Avatar
snarfblamFinding path/filename associated with extension snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

What you are looking for are file associations. It's easy to find examples that show how to create a file association, but there aren't many examples that show how to examine existing file associations.

To make things more confusing, there are different types of file associations. You have "commands," which you see when you right-click a file (for example, when I right click a .PNG file, I get the commands Preview, Edit, and Print). One of these commands can be the "default" command, in which case this command is executed when you double-click the file.

There are also "open with" associations. Each file type has a list of applications that is shown in the "open with" list when you right-click a file. If there is no default command, I believe that the first "open with" association is used when you double-click a file.

So-called "perceived types" can also come into play. For example, if a file's perceived type is "text" and a file-type has no commands or "open with" associations, the file will be opened with notepad. I honestly have no idea how perceived types are associated with programs.

As far as accessing association data, the starting point would be in HKEY_CLASSES_ROOT. You'll find a key for each file type, whose name starts with a dot. For example, the key for PDF files would be "HKEY_CLASSES_ROOT\.pdf". From there things can get confusing. It looks to me like the default value can specify the name of another key within HKEY_CLASSES_ROOT that contains the commands. Alternatively, there can be a sub-key called "shell" that contains commands. There is the open with list, as well as a list of "OpenWithProgids". I would imagine that OpenWithProgids reference more keys that identify programs for "open with," but I don't know where these keys would be located. The perceived type is simply specified as a value within the file extensions key.

All these things need to be taken into consideration to figure out how an arbitrary file type is opened. If your needs are more specific, things might be a bit simpler.
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 06-24-2011, 03:52 PM
AtmaWeapon's Avatar
AtmaWeaponFinding path/filename associated with extension AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

If you just want to open a file in its associated editor, the Process class will do so if you use a ProcessStartInfo with UseShellExecute set to True.

If you want to make some kind of list of file associations, it's going to be painful. May as well just tell your users how to get to that dialog via Windows Explorer or the "Set Default Programs" control panel widget.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 06-24-2011, 04:22 PM
stokeentertainm's Avatar
stokeentertainm stokeentertainm is offline
Contributor
 
Join Date: Jan 2005
Location: Stoke-on-Trent, UK
Posts: 439
Default

Thanks for the replies guys, really appreciate it.

I've poked around in the .pdf section previously as I knew it had something to do with that. But as you say, the data in there can be a bit confusing and points to other unique locations.

Sorry I should have been more specific. The example I gave is exactly what I'm trying to do really. I'm try to find the fully qualified path of the PDF reader, whatever that might be. I understand it's bad practice to assume that everyone's reader is in the same location so I want to do this properly.

I want to actually pass parameters to the PDF reader so I need to know the location of it in order for this to work. If I just call the PDF file with the Process.Start method the parameters do not get passed correctly.

I hope that makes sense.
Reply With Quote
  #5  
Old 06-30-2011, 10:01 AM
stokeentertainm's Avatar
stokeentertainm stokeentertainm is offline
Contributor
 
Join Date: Jan 2005
Location: Stoke-on-Trent, UK
Posts: 439
Default

Can I assume I didn't make sense?
Reply With Quote
  #6  
Old 06-30-2011, 10:03 AM
AtmaWeapon's Avatar
AtmaWeaponFinding path/filename associated with extension AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

How are you trying to pass the parameters with Process.Start()? It's odd that it wouldn't work.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 06-30-2011, 11:41 AM
stokeentertainm's Avatar
stokeentertainm stokeentertainm is offline
Contributor
 
Join Date: Jan 2005
Location: Stoke-on-Trent, UK
Posts: 439
Default

Well, I need to pass the parameters to the Adobe application such as /A as well as the filename, so there are two possibles :-

1. Process.Start("MyPDF.pdf","/A")
2. Process.Start("acrord32.exe","c:\MyPDF.pdf /A")

The first one will allow the shell to automatically open the Adobe application and open the file specified but the Adobe application ignores the parameters after the filename.

The second one opens Adobe directly and passes the entire command line to it. It works that way so my only issue is to discover where the acrord32.exe file resides.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension Finding path/filename associated with extension
Finding path/filename associated with extension
Finding path/filename associated with extension
 
Finding path/filename associated with extension
Finding path/filename associated with extension
 
-->