Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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=-

Whatever thy hand findest to do, do it with all thy heart - Jesus
Posted
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...

Glenn "Mykre" Wilson, DirectX MVP

Inner Realm

Managed DirectX and Game Programming Resources

  • 3 months later...
Posted
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.

Ilya
  • Leaders
Posted (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 by snarfblam
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...