我如何获得自定义文件类型路径 [英] How I Get Custom File Type Path

查看:98
本文介绍了我如何获得自定义文件类型路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#中创建了一个类似应用程序的编辑器。

所以这个应用程序将创建一个项目,它将有一些自定义文件类型。

我需要打开这个我的编辑器应用程序中的文件。

但我能够获得可执行文件路径,但在获取自定义文件路径时遇到问题,以及如何在将文件加载到编辑器时获取自定义文件路径

解决方案

1.您的项目文件应该是一个文本文件,建议为XML,其中包含有关项目中使用的所有自定义文件的详细信息。



2.属于项目的所有自定义文件应存储在同一文件夹(项目文件夹)中。



3.当你打开一个项目文件时,你应该使用系统OpenFileDialog类。 [ ^ ]。然后使用属性 FileDialog.FileName ,您将找到文件全名,包括其路径,您可以使用它来访问其他自定义文件。

您好,



我不确定我是否理解您的意思,但我认为您已经创建了该应用程序。您有一些与您的应用程序关联的文件。当您双击该文件时,您的自定义编辑器会启动,但您不知道如何获取双击的文件。我对吗?如果是这样,那么请看下面。



双击文件路径通过启动参数发送到应用程序。

所以,如果你有自定义编辑器for exapmle C:\ editor.exe和示例C中的自定义文件:\ file.cus应用程序的参数如下所示:

C:\ editor.exe C: \ file.cus



如您所见,文件路径作为第一个参数发送。如果您将文件与此应用程序相关联,下面的代码将向您显示详细信息。它只是简单地抛出发送给程序的参数数量和下面的每个参数。



 程序
{
静态 void Main( string [] args)
{
Console.WriteLine( String .Format( Args.Length:{0},args.Length));

foreach String s in args)
Console.WriteLine(s);

Console.ReadKey();
}
}





希望有所帮助。



问候,

BJ


I have created a editor like application in c#.
so this application will create a project which will have some custom file types.
and i need to open this files in my editor application.
but i am able to get the executable file path but facing problem while getting the custom file path, and how i get my custom file path while loading the file to editor

解决方案

1.Your "project file" should be a text file, recommended to be an XML, that will contains inside the details about all custom files used in your project.

2.All custom files that belong to the project should be by stored into the same folder (project folder).

3.When you will open an "project file" you should use the system OpenFileDialog class.[^]. Then by using the property FileDialog.FileName you will find the file full name, including its path and you will can use it to access the other "custom files".


Hello,

I am not sure if I understand what You mean, but i assume You have created the application. You have some files which are associated with your application. When you double click on the file, your custom editor starts, but you don't know how to get the file that was double clicked. Am I right? If so, then look below.

Double clicked file path is beeing sent to the application via the startup arguments.
So if You have custom editor for exapmle C:\editor.exe and custom file in example C:\file.cus the parameters to the application will look like below:
C:\editor.exe C:\file.cus

As You see, the file path is sent as first argument. The code below will show You the details, if You associate the file with this application. It just simply prits the number of arguments sent to the program and each of the arguments below.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(String.Format("Args.Length: {0}", args.Length));
            
        foreach (String s in args)
            Console.WriteLine(s);

        Console.ReadKey();
    }
}



Hope it helps.

Greetings,
BJ


这篇关于我如何获得自定义文件类型路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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