Click here to Skip to main content
Rate this: bad
good
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
Edited 26-Feb-12 8:47am
v2
Comments
SAKryukov at 26-Feb-12 14:43pm
   
The language is called C++/CLI. Please change the tag and the name of the language in the text. --SA
SAKryukov at 26-Feb-12 14:47pm
   
OK, I did it for you because I needed other improvements. --SA

1 solution

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

Solution 1

Here are the answers:
 
  1. Use System.IO.File, please see:
    http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx[^].
  2.  
  3. 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):
    http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx#Y0[^].
  4.  
  5. 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:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].
 
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[^].
 
—SA
  Permalink  
v3
Comments
Espen Harlinn at 26-Feb-12 17:33pm
   
Will surely help :)
SAKryukov at 26-Feb-12 19:27pm
   
I think so. Thank you, Espen. --SA
Wilmer Lameda at 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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 422
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 250
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 26 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid