I want to right-click on a text file and "Open With..." it with my own program, but I can't find any information on how to do that. I want to make my program in C++ or with WinForms (C#).
I want to open that file and to use my program as an interpreter on a small "homemade programming language", so I want to pass the data from the file directly to my program.
Can anyone help me?
*hope I'm clear enough on what I'm trying to do.
I'm just gonna to answer your Question for C#. If you still need C++ support you can tell me.
Option 1 - Drop down:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:
As you can see in the Picture: the Program accepts Arguments (args String Array)
If you drag & drop your file on your .exe, the filepath of the file you dropped will be saved in the args String Array. Now you can read the file (for example with the File-Class).
Option 2 - Right Click -> Open with my Program:
For that, you can simply add a new entry in HKEY_CLASSES_ROOT\Directory\Background\shell (Windows Registry) to register you Program as a "Right Click Menu Program".
Here is a detailed How-To:
https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/
After you added your Program to the Windows Registry you can proceed as shown in Option 1 (args).
Any more questions? Let me know.
Greets
Bennet
EDIT:
Sorry, didnt really read the comments :D but i guess your Question is answered. I will let this stay here for future readers which dont read the comments either ;)
Related
I'm working with a simple program that has to read data from a txt file and than display it. The thing is that i would like to read a specified extension files (for example .log) automatically.
So, i would like to do it as a simple Windows user - double click file and than the program opens. The problem is that this program is working but it's nor loading the file on start and tbh i have no idea if I should program it somehow? Any hints?
Thanks!
The easiest way to make it load the file automatically is to allow it accept the file path as a parameter and then do a load operation. As for having your program open automatically when a user double clicks on that file type I would recommend checking out this CodeProject
Sound like you want to associate file type with your application. This is done via windows registers. Try for example this article http://msdn.microsoft.com/en-us/library/windows/desktop/hh127451(v=vs.85).aspx
as a starter of c# (And honestly not really loving the visual express c# environment) I'm in need of a back-up function to finish off my program.
I have 4 xml files in the /Data folder (In my project's root)
Now, what I want to do is back these files up in a file-save sense.
When a user clicks the "Back-up 1.xml!" button I want the program to open a saveDialog which automatically saves a pre-defined XML file (/Data/1.xml), to wherever the user wants, under whatever name the user wants.
However, I just cannot get googled how to make c# preselect that file. I only get these plugins from MSDN (which isn't very usefull either)
Any help would be appreciated, thanks in advance!
It looks like you need to copy a file from one location to another one.
Here is another StackOverflow thread that looks similarly to yours:
Copy a File
Esentially, the only thing you need to do:
System.IO.File.Copy(oldPathAndName, newPathAndName);
You can get newPathAndName from user input. You know oldPathAndName already.
I am new to programming and want to write a simple program in C#. I will be using VS Express to compile my code.
Goal:
I want to write a program that will search within a directory for all files that were created by a particular author. (Author is found by right clicking the file, opening properties, selecting the details tab and there is a field called Author with a name next to it). If the Author is the specified author I'm searching for, then I want it to copy the file to a new folder.
The end goal will be that all files created by this particular author will be in one folder.
Is there an easy way to create this program using a windows forms application in VS express? I was thinking you click a button, a message box appears that you select the directory you want, then another message box appears and asks which author you want to search for. Then a third message box appears asking where you want to save the new folder to. then the program does everything else.
Any help pointing me in the correct direction to write a program like this, or providing code would be greatly apprecaited. thank you.
Check out this:
http://wiki.terrasynq.net/tutorials/c-add-and-edit-ntfs-custom-properties/
It shows how to use OleDocumentProperties to read and edit properties.
I've written a log parser, with some generous and insightful help from the SO community:
Keeping the UI responsive while parsing a very large logfile
Now, I'd like to be able to right click one of these logs, select "MyNewLogParser" from "Open With.." and see it open in my new program.
This would require me to
Change something about my XP installation to show my program in the dropdown list
Change the program so that it knows to open the selected file and run the parsing.
What do you call these things, and how is it done? I don't know what to search for...
To open the selected file, you need to implement command-line parameters. Take a look at your Program.cs file and the Main function.
You want its signature to look something like this:
static void Main(string[] args)
{
}
The args array will be the array of command-line params passed to your application. So if you ran MyNewLogParser myLog.txt, the contents of args[0] would be myLog.txt.
For the OpenWith... menu, you'll need to modify the registry. Search for the "OpenWith" key in Regedit and you'll find it. On my machine (Windows 7), it's in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts. I'm not sure on the exact details of how it works, but Google should be able to help you out from there.
If you don't want to do it programmatically, I'm pretty sure there's some menu item that allows you to select the application that will open a file. Don't recall what it is on XP, though. Alternatively, you can associate a file extension with your application through a tab in the Folder Options dialog, so that double-clicking it opens your application.
Assuming that your file logs have specific file extension, you need to add OpenWithList keys in the registry. See this MSDN page for more information:
http://msdn.microsoft.com/en-us/library/bb166549%28VS.80%29.aspx
So I'm starting my first actual Program in C# now, and just before I dig into the actual functions, I'm asking myself about localization of a Program.
I thought, a .resx is nice for the language-variables to store. But how can I get that into the settings? I see there is a .settings file, where I can assign Settings for the program, but how can I add my language.resx to these settings, so if there are several installed the user can select which language to use?
Furthermore, I'm designin the program using the winform designer - how can I tell a control to use a string of the resourcce as a text rather than type it in by hand?
I'm sure there are a bunch of tutorials out there concerning my issues, but 2 hours of searching haven't got me anywhere, so if anyone has some suggestions for me, I'd be very thankful =)
This seems to be similar to question 1142802, so maybe that is a good place to start.
ed:
It depends on the control a bit I guess, but for a menu you could create a method that defines it's contents.
You'd then be able to do something like menuItem1.Text = string.Item1Text.