Click here to Skip to main content
12,897,739 members (55,704 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++/CLI
Hi, guys!
Sorry to ask you this, but, after researching the topic, I still haven't gotten anywhere. And I'm new at Visual Studio C++/CLI, too!.
I'm using two types of data files in my application:
a) arrays (to be used in comboboxes as menu items), and
b) structures (to hold the data users will be accessing).

I want to save them all to disk, so they'll be ready for the program when it starts, instead of creating them everytime.

I'd be grateful if you helped me with this, specially on how to:

  1. Find out if the file already exists

  2. Save the file to disk, after creating it

  3. Open it for use within the application.

Thanks in advance.
Posted 26-Feb-12 7:45am
Updated 26-Feb-12 8:47am
SAKryukov 26-Feb-12 14:43pm
The language is called C++/CLI. Please change the tag and the name of the language in the text.
SAKryukov 26-Feb-12 14:47pm
OK, I did it for you because I needed other improvements.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here are the answers:

  1. Use System.IO.File, please see:[^].

  2. There is no such concept. The concept is: you open file/stream and write to it. The file is finally saved (flashed) on disk when you close it. You can also explicitly flash. If a class implements the interface IDisposable, you can just call it's Dispose method, which is the case if you use the class System.IO.StreamWriter (most recommended for write-only in text form):[^].

  3. By default, all files are opened for exclusive access. You cannot open it again until it is closed. This is the best option for most cases.

If you want to store your classes and structure, consider using serialization instead of explicit use of files.

The best method of serialization is using Data Contract. This approach is the most robust, non-intrusive and easiest to implement. You can store and load (restore) any arbitrary object graph in XML or JSON, even if the graph is not a tree (contains circular reference paths).

Please see:[^].

For more detail, please see my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

Espen Harlinn 26-Feb-12 17:33pm
Will surely help :)
SAKryukov 26-Feb-12 19:27pm
I think so. Thank you, Espen.
Wilmer Lameda 28-Feb-12 4:12am
THANK YOU. I'm trying to get the syntax right. Will let you know when I solve it.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 26 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100