c# - 打开自定义文件,args 始终为空

标签 c# .net windows winforms

<分区>

我有 C# WinForm .NET 4.5 应用程序。我设置项目 -> 属性 -> 发布 -> 选项 -> 文件关联。这部分似乎有效,因为它设置了我选择的图标,如果我双击带有自定义扩展名的文件(在本例中为 *.psi),它会打开我的应用程序。但是我很难获得双击的文件名。不知何故,我的 static void Main(string[] args) args 总是空的。 我使用 ClickOnce 部署方法。

任何人都可以帮助我解决我缺少的用我的应用程序打开自定义文件的问题。

static void Main(string[] args)
    {
        if(args.Length > 0)
        {
            MessageBox.Show(args[0]);
        }else {
          MessageBox.Show("args is empty!");
        }

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        DevExpress.Skins.SkinManager.EnableFormSkins();

        UserLookAndFeel.Default.SetSkinStyle(Properties.Settings.Default.ActiveSkinName);


        Application.Run(new MainForm(args));
    }

最佳答案

找到解决方案 here.

When you publish an app with ClickOnce and then launch it by double-clicking an associated file, the path to that file actually gets stored here:

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]

See MSDN's documentation for it here:

http://msdn.microsoft.com/en-us/library/system.runtime.hosting.activationarguments.aspx

Plus a tutorial on adding file associations to "Published" projects:

http://blogs.msdn.com/b/mwade/archive/2008/01/30/how-to-add-file-associations-to-a-clickonce-application.aspx

关于c# - 打开自定义文件,args 始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28732078/

相关文章:

node.js - 在 Electron 应用程序的 Squirrel 事件中执行 createShortcut

c# - 无法删除撇号

c# - MS2015 中的 MvcBuildViews 需要很长时间

c# - 使用linq计算平均值而不分组

c# - 如何防止无边框 Windows 窗体在调整大小时闪烁(C#)?

.net - 如何在VB.NET中画一条线

c# - 在 Java 中复制 .NET 排序

c - 从 CreateProcess 获取 PROCESS_INFORMATION

windows - 如何在 Windows 上抑制控制台窗口?

c# - 尝试在接口(interface)的实现中进行转换