473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Append into file

111 100+
Hi

I want to append one text from textbox1 only at beginning and textbox2 at the end of the file. How do i Do?
Dec 18 '07 #1
4 1541
lotus18
866 512MB
Hi

I want to append one text from textbox1 only at beginning and textbox2 at the end of the file. How do i Do?
What do you mean by file? As a filename? or a as a file itself? What version of vb are you using?

Rey Sean
Dec 18 '07 #2
baburk
111 100+
I am working in VB.Net

The file type is .txt
Dec 18 '07 #3
debasisdas
8,127 Expert 4TB
Append means to add to the end of the file with existing data. Since your requirement is different.

1. Read the content of the entire file.
2. Concatenate the text1 at the beginning and text2 at the end and then
3. Overwrite the file.
Dec 18 '07 #4
baburk
111 100+
I did like this

Expand|Select|Wrap|Line Numbers
  1.         Dim FILE_NAME As String
  2.         Dim objFile As System.IO.File
  3.         Dim objRead As System.IO.StreamReader
  4.         'Dim objWrite As System.IO.StreamWriter
  5.         'Dim intFileNum As Integer
  6.  
  7.         FILE_NAME = My.Application.Info.DirectoryPath & "\test.txt"
  8.         Dim LineAll As New System.Text.StringBuilder(CInt(New System.IO.FileInfo(FILE_NAME).Length + txtBefore.Text.Length + txtAfter.Text.Length))
  9.  
  10.         ' intFileNum = FreeFile()
  11.  
  12.         If objFile.Exists(FILE_NAME) Then
  13.             objRead = objFile.OpenText(FILE_NAME)
  14.             If txtBefore.Text <> String.Empty Then
  15.                 LineAll.Append(txtBefore.Text & vbNewLine)
  16.             End If
  17.             While objRead.Peek <> -1
  18.                 LineAll.Append(objRead.ReadLine() & vbNewLine)
  19.             End While
  20.             If txtAfter.Text <> String.Empty Then
  21.                 LineAll.Append(txtAfter.Text & vbNewLine)
  22.             End If
  23.             'FileClose(intFileNum)
  24.             objRead.Close()
  25.  
  26.             'Clear the text in the file and write into the file
  27.             objFile.WriteAllText(FILE_NAME, LineAll.ToString())
  28.         End If
  29.  
  30.         If (LineAll.Length > 0) Then
  31.             RichTextBox1.Text = LineAll.ToString()
  32.         End If
Dec 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nico Grubert | last post by:
Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: >>> f = open('/tmp/myfile', 'w')...
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
by: Matrix | last post by:
Greetings I want to append records in a XML file,I use XMLTextWriter,but i found it only create a XML file,not append records in exist XML file.why?...
4
by: Amy L. | last post by:
It is my understanding that in order to append XML to a file you would have to read the file in as an XML document and insert the node. However, what if the file is close to 1GB in size? Would you...
14
by: vbMark | last post by:
Greetings, This seems like it should be simple but I can't figure out how to do this. I just want to append binary file 2 on to the end of binary file 1. Sample code please? Thanks!
5
by: Simone M | last post by:
Here is my problem: I need to append a string to a file every time the user downloads this file. The string is different for every user. I would like to append the string to the file via ftp. But...
3
by: Mohan | last post by:
Hi I face a problem with the stl string append on our 32-bit SLES9 machine . (It is not happening on SLES9 64-bit machines and on SuSE 10). When we read a 179MB file into the memory,...
2
by: Kevien Lee | last post by:
Hi , I had a strang problam ,when i use StreamWriter to append to a file,i found that if i don't close the StreamReader it couldn't write the data into file,the code as folllow that: class...
2
by: Gaby Sandoval | last post by:
I have this code. The user can read teh record from the text file just fine. They can click the NEXT button and it reads the next record (which is just the next line from the text file). If the...
2
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). Therefore, I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.