如何创建保存文件的应用程序 [英] How to create app which saves a file

查看:83
本文介绍了如何创建保存文件的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请给我一些残忍,我需要创建一个应该能够创建文件并在任何自定义文件扩展名中保存在任何存储介质上的应用程序。



例如,就像你使用Microsoft Office创建.doc文件一样,并且点击创建的文件,你可以加载ms office并加载文件内容。程序。



简而言之,我如何创建一个将数据存储在文件中的应用程序,只需单击创建的文件即可检索此数据。



我不想使用任何第三方应用程序,如sql,access等来存储数据。



我很擅长C#,但我只需要一些关于如何开始使用这种应用程序的想法。



提前付款



我尝试了什么:



我在想序列化可能是出路,但我不太确定如何实现单击创建的文件并加载应用程序文件数据

Hi every,
Please give me some cruel, i need to create an application which should be able to create a file and save on any storage media in any custom file extension.

For example, like how you create a .doc file with Microsoft office, and on clicking on the created file, you can be able to load ms office and load the file content in the program.

In brief, how can i create an app which stores data in a file and i can retrieve this data by just clicking on the created file.

I don't want to use any third party app like sql,access, etc to store data.

I am good in C#, but i just need some ideas on how to start off this kind of app.

Thanks in advance

What I have tried:

I am thinking serialization could be a way out,but am not very sure how to implement the clicking on the created file and load the app with the file data

推荐答案

嗨!我不确定你在寻找什么,但据我所知,你希望能够将正则文本数据存储到正在运行的计算机的光盘上吗?如果您不想要数据库,那么如果存在更复杂的数据结构,您可以只编写规则文件或XML文件。如果您想减小尺寸,也可以对它们进行seriliaze或使用文件压缩。 (但只有在必要时)



单击.doc文件时Windows打开Office的原因是因为您的计算机已将扩展名与程序。



总而言之,只要您使用uniqe文件扩展名并将其与您的应用程序相关联,您就可以执行您想要处理的数据。 。然后,当然,您的应用程序可以反转序列化/压缩。



为了让您开始使用文件关联,我建议您在此站点搜索文章。我搜索了系统文件关联,在MSDN上我发现了这篇文章:文件关联示例(Windows) [ ^ ]



请注意左侧的导航栏以获取更多信息,并记下方框这将带您进入Windows 10部分。
Hi! I not sure what you are looking for, but what I understand is that you want to be able to store regulare text data onto disc of the running computer? If you don't want a database you can write just regulare files or XML files if there is more complex structer of data. You can seriliaze or use file compression on them as well if you want to reduce size. (But only if you have to)

The reason why Windows opens up Office when you click on a .doc file, is because your computer has associated the extension to that program.

So to sum up, you can do what ever you want to do with your data as long as you use a "uniqe" file extension and associate that to your application. And then of course, your application can reverse the serialization/compression.

To get you started on File association I recommend you to search this site for articles. I searched on "System File Association" and on MSDN I found this article: File Association Example (Windows)[^]

Do note the navbar on the left side for more information and do note the box that takes you to the Windows 10 section.


只是一些额外的信息:



将文件类型与应用程序关联时(您可以手动执行,也可以作为应用程序安装的一部分) - 双击文件时,将打开应用程序,并将文件路径作为第一个命令行参数提供。



这可以在
Just some extra info:

When you associate a file type with your application (which you either do manually, or as part of the install for your application) - when the file is double-clicked, your application is opened and the path to the file is supplied as the first command-line argument.

This is available in the args parameter of the
Program.Main(string[] args)

方法,它也可用应用程序中的任何地方

method, it is also available anywhere in your app in

Environment.GetCommandLineArgs()

,(但要注意第一个元素将是你的应用程序的exe)



对于通过ClickOnce部署的应用程序,您需要访问:



, (although, beware the first element will be your app's exe)

For an application deployed through ClickOnce, you need to access:

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData





对于WPF应用程序,您需要在App.xaml中处理启动事件:





For a WPF app, you need to handle the startup event in App.xaml:

<application x:class="XmlViewer.App" xmlns:x="#unknown">
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:XmlViewer"
             Startup="Application_Startup">
    <application.resources>
         
    </application.resources>
</application>







/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    private void Application_Startup(object sender, StartupEventArgs e)
    {
        // process the command line argument
        if (System.IO.File.Exists(e.Args[0]))
        {
            // do stuff here
        }
    }
}


这篇关于如何创建保存文件的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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