Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 17-May-16 17:17pm
Comments
Sergey Alexandrovich Kryukov 15-May-16 18:55pm    
It makes no sense at all.
—SA

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.
 
Share this answer
 
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
C#
Program.Main(string[] args)
method, it is also available anywhere in your app in
C#
Environment.GetCommandLineArgs()
, (although, beware the first element will be your app's exe)

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

C#
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData


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

XML
<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>


C#
/// <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
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900