Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everybody!

I have a Windows Form Application. It is a MP3 Player, it consists in a wmp.dll, a listview, and three buttons, one button shows me an OpenFileDialog, in which I can choose multiple songs, when I click OK in the Dialog it shows me the selected songs in the listview which has two columns: Title and Location;

I want a button to save the ListView's content so when I close the form and run it again, it will show me the "playlist" that I saved before.

First of all, I can't figure out how to do that.
Second, after searching on google, I tried to save the content with Xml, TXT, and no one of this methods got the problem solved.

Please help me with this problem, I'm breaking my head to solve it.

THANKS IN ADVANCE!
Posted

1 solution

It's better not to mess with XML or any other files by yourself, but to use serialization. Probably the best serialization method for you would be using Data Contract: http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].

This way, you can have any data model in the form of any arbitrary object graphs, save it in the file, and that restore it in memory as it was before saving. So, you work not with UI or XML, but with data. See also my past answers where I advocate this powerful approach:
Creating property files...[^],
How can I utilize XML File streamwriter and reader in my form application?[^].

—SA
 
Share this answer
 
Comments
ChrisCreateBoss 7-Jan-15 21:25pm    
Ok, thanks for your early response.

I am new to C#, I have not used complex coding yet, so, could you give me an example of how to apply it to my project?
Sergey Alexandrovich Kryukov 7-Jan-15 21:31pm    
Read the article. You will find the example. Then try to define the model to solve your problem and try serialization. Then, if you still face the problems, ask further questions. Why do you thing answering your question about the "example" should provide you better material?
—SA
ChrisCreateBoss 7-Jan-15 22:32pm    
Ok, and I said that because I don't understand the code provided in that article's example. As I said, I'm new to this type of coding.
Sergey Alexandrovich Kryukov 8-Jan-15 0:09am    
This is not "coding". No problem. Learn more of programming, theory and practice, and come back when you get more confidence. Everyone should solve problem according their capacity. Be more realistic. Set aside players, advanced graphics and perhaps UI, get to fundamentals.
—SA
ChrisCreateBoss 8-Jan-15 13:49pm    
I already got how to save my content in a .txt, now my problem is load it again in the listview.

Otherwise, DataContract did not work well for me. :3

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