I cannot find a solution anywhere to this problem. I've only seen bits and pieces of code that barely work to get some exe files associated in the registry to that particular extension.
What I want is the exact list the Windows Explorer context menu will give you if you go to the Open With item. If I have to do it with p/invoke that is fine, I just want the exact list that explorer would show. That would include the friendly name as well as the path to associated program.
The list I want to retrieve for a pdf:
The list I want to retrieve for a png:
It may be worth noting that Microsoft calls it the "Recommended Programs" if you attempt to choose by clicking "Choose default program..."
So how is that dialog populated? Because it must be using the same method for the Open With context menu.
There are some popular answers to this question on SO, but most of them only half work.
Example Answer #1
Example Answer #2
If the AssocQueryString function returned multiple results it'd be close to an answer, however I believe it can only get the actual program associated with it.
Related
For a project I have folders of images. An example folder might be ImagesOfDogs, and the images inside would be sequentially named (1.png, 2.png, etc.). I have a button, and when I press this button I want to open all of the images in a folder at once, in one window. I could make my own window, but I would rather use the default Windows program so the user can edit the photos. This would look like the following (just imagine that black thing is a really cute dog pic):
Let's say the path to a folder is a string titled sPathToFolderOfDogs. On my button click, I want a method like this:
private void OpenCoolPicsOfDogs()
{
Process.Start(sPathToFolderOfDogs);
}
Except that will open all enclosed files in an image viewing application, preferably whichever is the user default. I have tried:
Process.Start("PictureViewer", sPathToFolderOfDogs);
...which opens PictureViewer and does not open my photos in PictureViewer,
Process.Start(sPathToParticularImage1);
Process.Start(sPathToParticularImage2);
etc etc
...which opens each in a new window,
and possibly most creatively/desperately:
String[] arrayOfAllMyPathsToParticularImagesInTheFolder;
(put all the strings in the array)
Process.Start(arrayOfAllMyPathsToParticularImagesInTheFolder);
Which just crashed. I know opening folders in applications through Process.Start should be possible because it is done in the docs here.* Is there a way to do it with images?
*relevant code from link:
// Start Internet Explorer. Defaults to the home page.
Process.Start("IExplore.exe");
// Display the contents of the favorites folder in the browser.
Process.Start(myFavoritesPath);
Thanks!
It turns out my question was a duplicate. However, I am not deleting it, as the powers that be suggest it is best to keep duplicates up as a "signpost" informing future searchers where the true path lies.
Here is the answer to my question (or more specifically, about half a dozen equally functional answers to my question).
TL;DR: The solution I am now using is from #bruceatk in the above link.
I am using Visual studio 2010 to create CodedUI Scripts.The application under Test is a web based Loan origination application .
I am automating a part where user enter's zip code and clicks on search.
when I enter zip code manually and click on search the response is received instantly.
But when the same is done with code,Zip code is successfully sent and search button is clicked but application dose not respond.
Mouse.Click(ContactInformation.ContactInformationForm.PropertyAddress.ImageZipLookup);
Just wanted to understand if this is a playback issue and is there a alternative for using mouse.click()
Most likely, the definition for the submit button is incorrect in your recording. Open the .uitest file, find the control in question in the tree, and open the SearchProperties in the properties of the control. Verify that against the source on the page, and then try again. It's possible that the recording identified a parent HtmlDiv object or something that's receiving the input rather than the button itself (or link, if that's the case).
Personally, while I'm looking at the SearchProperties, I'd remove any properties that are unnecessary. If there's an ID or unique class for the object in question, I'd stick with that alone rather than identifying six or seven other traits that may not be correct on each run (.css styles, inner text, etc. can change depending on your app).
Just be sure you edit the SearchProperties in the UI rather than the text editor, as the .designer.cs file is recreated each time you run the Test Builder, so you would lose any changes you make directly to that file.
I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.
I am working on a Version Control/File Sync System for Windows. It would be great to have a checkbox at the bottom of the classical save file dialog with the option to check/uncheck for my file versioning.
Is it possible to listen for opened save file dialogs by any program (word etc.) and replace/override that dialog with a customized one (with an additional checkbox)?
If the checkbox is checked, another window should pop-up where the user could enter some additional metadata. After that the data is stored in a local database.
I already worked with the approach by dmihailescu (link provided) but it's very complex and I do not know how to modify that example to listen for opened save file dialogs by other programs.
http://www.codeproject.com/Articles/19566/Extend-OpenFileDialog-and-SaveFileDialog-the-easy?msg=4779306#xx4779306xx
Another approach is to use the FileSystemWatcher but that's very expensive to watch the whole system and it's not very comfortable because the user has to be asked for any created file if he/she wants to version control it.
I hope someone could help me to solve that problem or has some additional tips / approaches.
Thank you.
Edit: Use-case
A user has to write a documentation and creates a new word-doc. When he/she clicks the Save as menu entry of word, my customized save file dialog should pop-up with a checkbox at the bottom, if this file should be versioned or not. If the checkbox is "active" a new window should appear where the user could enter additional metadata. After that the data should be stored in local database.
In my case, only the metadata (like the path etc.) should be stored in the database. Let's suppose a user stores the same file in two different directotries (one file is "older" and one file is the current one). If the user opens an older version of this file, my system should recognize that a "newer" one is already stored in another place and synchronize those files.
That should just be a very easy example.
You have two pieces of functionality: save and version-control. Both of the tasks are actually rather complicated. Therefore you shouldn't mix them. You better off using standard Windows API to save file and do not change that. Think about how you'd support several different Windows releases and how painful that would be.
I assume you have your own UI, and do not integrate with, say, Windows Explorer (like Tortoise Svn or Dropbox). In this case you can do version-control magic first and then just save the end file using standard API.
If you do integrate with Windows Explorer, I suggest you to have a look at Tortoise svn source code.
How to open files from explorer into different tabs. I can associate an open with menu with the file type, now when I already have the program working, how to open the new file into another tab, instead of new program.
How to find the already running process exactly, not with the name and send the filename to it.
Let me make myself clear: I want my app to be single instance, so that when user select 10 text files and press enter key, my application will open all the 10 text files into 10 tabs, instead of creating 10 processes. How to do that? How to communicate between various instances of the same process.
EDIT SOLVED: Implemented the functionality using WM_COPYDATA in C# and the SingleApplication class from codeproject.
I am not quite sure what you mean in this question. Are you trying to open Windows Explorer windows into one window with tabs? If that is the case, then I recommend you look into QT TabBar, which extends Windows Explorer to allow for such behavior.
Or perhaps you are trying to have a link open to a new tab in a web browser. If that is the case, this behavior is defined by the web browser itself. For Internet Explorer 7, you can set this behavior under Tools > Internet Options.
In the General tab, click the Settings button next to the "Tabs" section. You will want to set the "Open links from other programs in:" option to open a new tab.
Keep in mind that this behavior is defined by each user, and you can't ever make any guarantees that they will have the same browser settings as you do.
After reading your comments, I think I understand a bit better. It sounds like you want your application to only allow one instance at a time. Since you tagged this post C#, I will assume that is what you are writing your program in.
Codeproject.com has a great tutorial on how to make your program only allow a single instance.
Here is a snippet of code from their site:
static void Main()
{
if(SingleInstance.SingleApplication.Run() == false)
{
return;
}
//Write your program logic here
}
You would want to write code just before the return statement to have the existing instance open the file in a new tab.
If you are able to provide detailed information about what your program is doing, we might be able to help you with some of the specifics.