-1

I have an array of randomized music files. Is there a way to save an array in my .exe without creating a save file?

This is my array string[] playlist = new string[] { };

It is created under public partial class frmMain : Form when the program starts up.

I tried looking over How do I save an array of objects in a C# ASP.Net Sesssion? but i don't understand anything there.

Community
  • 1
  • 1
  • 1
    You cannot modify your EXE while it's running. You need to store it in a file, database, or the registry. – SLaks Sep 06 '15 at 02:20
  • No - there is no way to persist data into the executable. The executable is created at compile time. You can save data with a settings file. ASP.NET is for web programming. – Ian R. O'Brien Sep 06 '15 at 02:21
  • This would be extremely difficult, impractical, and, in some ways, impossible. Why do you want to do this? Perhaps there is another option for what you are trying to accomplish! – LVBen Sep 06 '15 at 02:22
  • I am creating a media player which has a playlist which is constantly modified and i need to save those playlist modifications for everytime the user opens the .exe (ultimatley to use the modified playlist, sorry im bad at wording things). – Richard Romanchik Sep 06 '15 at 02:26
  • 2
    Save them to a file under `Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)` folder – torvin Sep 06 '15 at 02:28
  • If it's a Forms program use the Load event to load the playlist from disk. You can save the playlist in an M3U file so it is compatible with other players. – Ian R. O'Brien Sep 06 '15 at 02:28
  • If I can't save it into my exe which option is the best for saving an array? – Richard Romanchik Sep 06 '15 at 02:29
  • @ Ian R. O'Brien could you give me a how to make m3u files link? I'm having trouble finding one. – Richard Romanchik Sep 06 '15 at 02:40
  • Are you using Windows Forms or ASP.NET? Please tag your question appropriately. – Shimmy Weitzhandler Sep 06 '15 at 03:11
  • I don't now, I assume ASP.NET because it is ".NET Framework 4.5" – Richard Romanchik Sep 06 '15 at 03:13

2 Answers2

0

If you want the settings to persist while the application is off, your best bet is to interfere with the file system.

See this question for several options that enables storage of settings.

Community
  • 1
  • 1
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
0

Ok m8 it seems there is no way to save something in an .exe so I suggest you save your array to a .txt file.

To save:

'string[] playlist = { }; System.IO.File.WriteAllLines("c:\save file.txt", playlist);'

To open:

string[] playlist = System.IO.File.ReadAllLines("I://LDSS Mix.txt"); for (int i = 0; i < playlist.Length; i++) { listBox1.Items.Add(playlist[i]); }