Best way to insert new data into files?
I need a bit of advice. I want to insert new data into an existing file but keep the current information that is in the file intact. When I used to do this in Perl I did it very slowly by reading line by line into a large varible until I found where I wanted to put the new info in, then appeneded the info to the varible and finished reading the file to the varible. Well needless to say that took a lot of memory and CPU time. While I have not looked much into it for C# I have to head off to my 9 hour shift of work right now and though I would pose the question to see what you guys think while I do a bit of searching when at work. So what would you recomemnd for the easiest and fastest way to insert information into an existing file?
Re: Best way to insert new data into files?
What is the format of the file? It is your own, or another? Can you use any driver? And not why to use a database? It seems exactly like job for it.
Re: Best way to insert new data into files?
I would go with boudino's recommendation. By the look of it you would want to place the new information into a specific place in the file (i.e. amongst existing data). I think this is a complicated way of doing it. If you are concerned about order go for a database storage system. If for some reason you want to avoid the database option go for XML format. The XML option won't be very quick (if you don't have lots of data you wouldn't notice any difference) as you would have to load the whole file into memory, do the update and then save the file. If you were not concerned about the order you could just open the file and append the data at the end...
Re: Best way to insert new data into files?
It would be .aspx pages with no code behind. What I am doing is making a CMS for a website I run. There are pre-created files that would just be copied to new locations for information that is stored in the database but some other files I just saw it as a waste of DB space to store as they would be always static information. One example would be for a PS2 game the character discriptions. Once written that information would only change if there was a type-o so why waste the DB space and overhead to dynamicly generate that page every time it was loaded. Why not just create a static .aspx page to serve that information up?
Although now that I think of it I can change the code idea I had in my head to instaed of reading a template file and inserting the information into the template I can move the header and footer of the template into the c# varibles and generate the hole file from scratch each time that script is called.
Re: Best way to insert new data into files?
Re: Best way to insert new data into files?
Quote:
Originally Posted by
jonlist
Refactoring is great
What do you mean refactoring?
Re: Best way to insert new data into files?
Sorry, i just meant, that it is great when you encounter a problem that makes you realize that the structure of your program can be improved
Re: Best way to insert new data into files?
and what's the relavance of the revactoring to the OP's question?