3. Prove position of quotation mark at beginning of string - VB.Net
4. Resetting IO.StreamReader to beginning of file
I am using an IO.StreamReader to read the contents of a text file. It all works just fine. However, I do not know of a way to move back to the beginning of a file. For example, let's say that I read in five lines from the file, or all of them for that matter. How do I then point the IO.StreamReader back to the beginning of the file? I would imagine that I could use "New IO.StreamReader(sFileName)" to create a new IO.StreamReader pointing to the file, and starting back from the beginning. I am just wondering if there is another way to do this (i.e. some method or something).
5. Wierd issue with listbox and Begin...Endupdate - VB.Net
6. Inserting text at the beginning of an existing text file
Hi,
I'm using Visual Studio 2005. I am developing a web application that uses
the FileUpload control to upload text files to a directory on a webserver.
This works fine.
However, for me to be able to further process the files, I need to insert
some data at the BEGINNING of the text file. All the solutions I've seen
either append the text to the end of the file, or overwrite the data at the
start of the file, or read the entire file into a string
("StreamReader.ReadToEnd"), concatenate, then write the string back to the
file (innefficient).
Please note:
The text files in question could be up to 5000 lines long with each line
being up to 200 characters long (+- 1 million chars), and storing all that in
a string may be a strain on resources, so the solution must be efficient.
Isn't there a way to directly access the file to do the insert?? Something
like:
1. Convert text file to a "direct access file"
2. Insert data at the begining
3. Convert "direct access file" back to a text file
So far my code is as follows for the submit button on the page (see my
commented lines):
Imports System
Imports System.IO
...
Protected Sub butSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles butSubmit.Click
... (working code)
If FileOK Then
Try
Dim strNewFileName As String = path & Now().Ticks.ToString &
"NewFileName.txt"
Dim strRefNo As String = "1234567890"
Me.FileUpload1.PostedFile.SaveAs(strNewFileName)
'The text file now contains:
'XXXXXXXXX, "qwerty...."
'YYYYYYYYYY, "asdfgh ..."
'etc.
'this is where I need a code snippet .....
'----
'---- INSERT strRefNo at the BEGINNING of the text file represented by
strNewFileName ----
'----
'After the insert, the text file must be on the webserver and now contain:
'1234567890
'XXXXXXXXX, "qwerty...."
'YYYYYYYYYY, "asdfgh ..."
'etc.
Me.lblResult.ForeColor = Drawing.Color.Black
Me.lblResult.Text = "File successfully uploaded!"
Catch ex As Exception
Me.lblResult.ForeColor = Drawing.Color.Red
Me.lblResult.Text = "File could not be uploaded."
End Try
Else
'display error message
Me.lblResult.ForeColor = Drawing.Color.Red
Me.lblResult.Text = "Cannot accept files of this type."
End If 'FileOK
... (working code)
End Sub
Any help will be appreciated.
7. the beginning of the end for VB? - VB.Net
8. append to the beginning of a text file
I want to add a new line to the begining of a text file. I dont want to write over existing data. How do I do this? the file is about 7 mb.