-
February 8th, 2010, 06:42 AM
#1
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?
-
February 8th, 2010, 07:45 AM
#2
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.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
February 8th, 2010, 08:43 AM
#3
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...
-
February 8th, 2010, 12:24 PM
#4
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.
-
February 8th, 2010, 04:45 PM
#5
Re: Best way to insert new data into files?
-
February 8th, 2010, 06:15 PM
#6
Re: Best way to insert new data into files?
Originally Posted by jonlist
Refactoring is great
What do you mean refactoring?
-
February 9th, 2010, 03:03 AM
#7
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
-
February 9th, 2010, 03:11 AM
#8
Re: Best way to insert new data into files?
and what's the relavance of the revactoring to the OP's question?
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|