创建自定义文件扩展名 [英] Create custome file extention
本文介绍了创建自定义文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要将一些文件扩展名与我的应用程序相关联,例如当用户双击该文件时,使用.ztr直接使用我的应用程序工作,我正在使用VS2012,C#,Windows 7我在这里模拟了这个示例
https://www.youtube.com/watch?v=s_YUcBxc5xM [ ^ ]
肯定有一些修改,比如修复导入Dll也放了faild。
I am tring to make some file extention associated to my application like make any file with .ztr work directly with my app when user double click that file I am using VS2012 , C# , Windows 7 I did simulate this Example here
https://www.youtube.com/watch?v=s_YUcBxc5xM[^]
sure with some modification like fix Import Dll put also faild.
public static void Register (string Ext,string Program,string Ico)
{
string prog = Path.GetFileName(Program);
RegistryKey file = Registry.CurrentUser.CreateSubKey("Software\\Classes\\"+Ext);//.osa
RegistryKey App = Registry.CurrentUser.CreateSubKey("Software\\Classes\\Applications\\" + prog);//osama.exe
RegistryKey Link = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + Ext);//.osa
file.CreateSubKey("DefultIcon").SetValue("", Ico);
file.CreateSubKey("PerceivedType").SetValue("","Text");
App.CreateSubKey("shell\\open\\command").SetValue("", "\"" + Application.ExecutablePath + "\"%1");
App.CreateSubKey("shell\\edit\\command").SetValue("", "\"" + Application.ExecutablePath + "\"%1");
App.CreateSubKey("DefultIcon").SetValue("", Ico);
//There is Change here you
Link.CreateSubKey("UserChoice").SetValue("Progid", Program);
Invoke.SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
}
推荐答案
我真的不知道会发生什么,部分原因是你没有定义'失败'。
我将从修改这两行开始:
I don't really know what happens, partially because you did not define 'failed'.
I would start by modifying these two lines:
App.CreateSubKey("shell\\open\\command").SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");
App.CreateSubKey("shell\\edit\\command").SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");
这样,两者都是可执行路径和命令行参数将包含在它们自己的引号之间。
This way, both the executable path and the command-line arguments will be enclosed between their own quotes.
看看这里:
C#:设置文件类型关联 [ ^ ] - 这是非常有趣的文章;)
和StackOverflow KB : As社交文件扩展与应用程序 [ ^ ] - 他们建议使用 ClickOnce [ ^ ]并且不要折磨自己编写自定义函数;)
Have a look here:
C#: Set File Type Association[^] - it is very interesting article ;)
and also StackOverflow KB: Associate File Extension with Application[^] - they suggest to use ClickOnce[^] and to not torture yourself writing custom functions ;)
这篇关于创建自定义文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文