开发者

visual C# open own file extension

开发者 https://www.devze.com 2022-12-25 23:08 出处:网络
I have made my own file type (.ddd) and I made a simple program to open this file type, but wenn I click on a .ddd file (on my desktop) my program opens only the file is not automaticly opend inside m

I have made my own file type (.ddd) and I made a simple program to open this file type, but wenn I click on a .ddd file (on my desktop) my program opens only the file is not automaticly opend inside my program.

How do I 开发者_StackOverflowdirectly open the file in my program when it opens?


The windows shell passes the filename to your program as a command-line argument. Your program needs to read its command-line arguments and open the file specified there.


Are you looking to register the file extension in the registry?


Did you include code in your Main() to read the commandline parameter? e.g.

static void Main(string[] args)
{
    string fileToOpen = "";
    if (args.Length == 1)    
       fileToOpen = args[0];

   ...
}

If you have done this, then I guess you haven't properly registered your program to open this file type. Right-click any .ddd file, select Properties, and where it says "Opens with:" make sure your program is shown. If not, click Change and browse to your program.


I slitly changed charles m's post and this works fine:

string[] args = Environment.GetCommandLineArgs();
string fileToOpen = "";
if (args.Count() == 2)
{
    fileToOpen = args[1];
}

thanks for your suggestions, Ecross

0

精彩评论

暂无评论...
验证码 换一张
取 消