rifter1818 Posted October 25, 2004 Posted October 25, 2004 The Challange to store a collection of hashtables(String Keys, Int Values || Doesnt have to be hashtables there just what i know how to use in c#, closest thing i know to good old maps in c++) for All the Files,Directories, And others (My Computer,drives,recyclebin...) as an embedded resource in an executeable that can be edited while the program is running (loads at startup saves at shutdown & or Backup Points). I guess ill break it down into two seperate questions 1) How would i add a textfile (something i can access with StreamReader/StreamWriter) as an embedded resource and access it with a) a StreamReader, and b) a StreamWriter. 2) Any suggestions on how to efficiantly store and access this data (which as im sure you can guess will get quite large very quickly)? Thanks in advance Quote
Simcoder Posted October 26, 2004 Posted October 26, 2004 1) How would i add a textfile (something i can access with StreamReader/StreamWriter) as an embedded resource and access it with a) a StreamReader, and b) a StreamWriter. 2) Any suggestions on how to efficiantly store and access this data (which as im sure you can guess will get quite large very quickly)? Thanks in advance Well, I can answer question one for you. Not sure about the second one. First off, if you have an embedded text file, you can only read from it, you won't be able to write to it because the file is already embedded in the exe. Lets say you have a textfile called TestData.txt. Add it to your project and set it as an embedded resource. If you don't know how, just let me know and I'll show you. Heres some example code you could use for a button that would read the first line of text from the embedded file. Note: you need to change "RootNameSpace" to the appropriate value for your project. Dim Read As StreamReader Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Read = New StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("RootNameSpace.TestData.txt")) 'Label1.Text = Read.ReadLine 'Read.Close() End Sub This probably won't be the solution your looking for because you want to be able to write data as well. If your just storing data locally, you can let your program create a textfile in some directory on the users pc and read and write to that instead of trying to do it with an embedded textfile. Let me know if you need help with that, I'll send you an example. -=Simcoder=- Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
rifter1818 Posted October 26, 2004 Author Posted October 26, 2004 Darn i was almost sure there was a way of editing Embedded resources (as counter intuitive as it sounds). Oh well guess its just gonna have to go in a regular text file.... Quote
Mykre Posted October 28, 2004 Posted October 28, 2004 Darn i was almost sure there was a way of editing Embedded resources (as counter intuitive as it sounds). Oh well guess its just gonna have to go in a regular text file.... Why not use an XML File... Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
samsmithnz Posted February 18, 2005 Posted February 18, 2005 I have an embedded XML file I'm trying to reference, which is in a sub folder. How do I reference it? I've tryed everything, but I can't seem to load it... Any ideas? Quote Thanks Sam http://www.samsmith.co.nz
ilya2 Posted February 18, 2005 Posted February 18, 2005 I have an embedded XML file I'm trying to reference, which is in a sub folder. How do I reference it? I've tryed everything, but I can't seem to load it... Any ideas? Using this code: string[] resourceNames = assembly.GetManifestResourceNames(); you can get the names of all embedded resources in assembly. Quote Ilya
Leaders snarfblam Posted February 20, 2005 Leaders Posted February 20, 2005 (edited) Isn't it considered very bad practice to store data in an executable file? I don't believe that .Net would provide any tools with such functionality [Edit]For the sake of clarity: I don't mean store data as in storing resources but saving user data or settings[/Edit] Edited February 21, 2005 by snarfblam Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.