允许自定义的文件,双击打开我的应用程序,同时加载的数据 [英] Allow a custom file to double click and open my application while loading it's data

查看:199
本文介绍了允许自定义的文件,双击打开我的应用程序,同时加载的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你犯了一个参考的窗口,打开.txt文件,就像,它可能会打开NOTEPAD.EXE和或Word.exe,在加载从文件中的文本到编辑器。我怎样才能做到这一点与我的桌面应用程序。我有它的自定义文件类型的扩展名为.mmi。我想这样,当用户双击此文件类型不仅会打开我的应用程序,但加载在它的数据到我的应用程序的相应区域。我知道如何设置自定义文件类型为我的应用程序设置,但如果我失去的是如何获取文件信息触发打开我的应用程序,这样我可以从它那里得到的数据。

例如。如果我打开一个.html和选择使用NOTEPAD.EXE,在HTML现在在新打开的文本编辑器打开。

这是一个从应用程序,而不是一个控制台,与主要具有的args开始关闭应用程序,柜面,帮助或改变任何东西。

下面的例子:

 公共部分类FormDashboard:表
{
    公共FormDashboard()
    {
        的InitializeComponent();
    }

    私人无效FormDashboard_Load(对象发件人,EventArgs的)
    {


         //我要得到什么文件触发的应用程序在这里开设,并相应地应用数据throurght的表单应用程序。

    }
 

解决方案

在回答你的问题是没有什么不同的WinForms应用程序和控制台应用程序。

.mmi 文件触发您的应用程序将是路径的args [0] 在您的应用程序的方法(假设签名主要(字串[] args))。

因此​​,了解什么 .mmi 文件是双击来触发您的应用程序将主要来自由 - 你告诉Windows打开之后。 MMI 与您的应用程序文件。

下面是一个例子 - 在这里我只是用一个文本文件 Test.mmi 和一个简单的控制台应用程序 ConsoleApplication1 对于在PoC:

  / *
 * Program.cs中
 * /

使用系统;
使用System.IO;

命名空间ConsoleApplication1
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            如果(args.Length大于0)
            {
                //打开并显示在双击.mmi文件中的文本。
                Console.WriteLine(File.ReadAllText(参数[0]));
            }

            //暂停5秒钟看到双击文件的文本。
            Thread.sleep代码(5000);
        }
    }
}
 

告诉Windows打开 .mmi 文件 ConsoleApplication1.exe ConsoleApplication1之后。 exe文件显示 Test.mmi文本),当我双击它:

这将不同于我所提供的的PoC的唯一的事情是什么,你需要做的是进来的的args文件路径[0]

Just like when you make a reference in windows, to open a .txt file, it may open NotePad.exe and or Word.exe, while loading the text from the file into the editor. How can I do this with my Desktop Application. I am having a custom file type for it with extension .mmi. I want it so that when the user double click this file type it will not only open my application, but load the data within it into the appropriate areas of my application. I understand how to set the custom file type for my application settings, but where I am lost is how to get the file info that trigger opening my application so I can get the data from it.

For example. If I open a .html, and choose to use notepad.exe, the html is now loaded in the newly opened text editor.

This is for a From Application, not a console application that starts off with main having args, incase that helps or changes anything.

Example below:

public partial class FormDashboard : Form
{
    public FormDashboard()
    {
        InitializeComponent();
    }

    private void FormDashboard_Load(object sender, EventArgs e)
    {


         //I want to get what file trigger the app to open here, and apply the data accordingly throurght the forms application.

    }

解决方案

The answer to your question is no different for a WinForms app and a console app.

The path of the .mmi file that triggered your app will be args[0] in your app's Main method (assuming the signature Main(string[] args)).

So knowing what .mmi file was double-clicked to trigger your app will essentially come for free - after you have told Windows to open .mmi files with your app.

Here is an example - where I just used a text file Test.mmi and a simple console app ConsoleApplication1 for a PoC:

/*
 * Program.cs
 */

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                // Open and display the text in the double-clicked .mmi file.
                Console.WriteLine(File.ReadAllText(args[0]));
            }

            // Pause for 5 seconds to see the double-clicked file's text.
            Thread.Sleep(5000);
        }
    }
}

After telling Windows to open .mmi files with ConsoleApplication1.exe, ConsoleApplication1.exe displays the text in Test.mmi (Whatever....) when I double-click it:

The only thing that will differ from the PoC I have offered is whatever you need do with the file path that comes in as args[0].

这篇关于允许自定义的文件,双击打开我的应用程序,同时加载的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆