473,382 Members | 1,814 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,382 software developers and data experts.

Filestream problem

Hi guys

I see blue line underneat the word FileStream in the following code in
line 2.
Can any one help me to find out what am I missing
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles Button1.Click
1 Dim DestinationLoc = "c:\Stream.txt"
2 Dim FS As FileStream = New File.Open(DestinationLoc,
FileMode.OpenOrCreate, _
3 FileAccess.ReadWrite)
4 Dim s As New StreamWriter(FS)
5 s.BaseStream.Seek(0, SeekOrigin.End)
6 s.WriteLine("This is an example of using file handling
concepts in VB .NET.")
7 s.WriteLine("This concept is interesting.")
8 s.Close()

End Sub
End Class

Sep 30 '06 #1
4 2881
I am using vb.net 2003

Sep 30 '06 #2
Dear khan,

from the VB.NET help:
Imports System
Imports System.IO

Class Test
Public Shared Sub Main()
' Create an instance of StreamWriter to write text to a file.
Dim sw As StreamWriter = New StreamWriter("TestFile.txt")
' Add some text to the file.
sw.Write("This is the ")
sw.WriteLine("header for the file.")
sw.WriteLine("-------------------")
' Arbitrary objects can also be written to the file.
sw.Write("The date is: ")
sw.WriteLine(DateTime.Now)
sw.Close()
End Sub
End Class

Best Regards,

HKSHK

khan wrote:
Hi guys

I see blue line underneat the word FileStream in the following code in
line 2.
Can any one help me to find out what am I missing
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles Button1.Click
1 Dim DestinationLoc = "c:\Stream.txt"
2 Dim FS As FileStream = New File.Open(DestinationLoc,
FileMode.OpenOrCreate, _
3 FileAccess.ReadWrite)
4 Dim s As New StreamWriter(FS)
5 s.BaseStream.Seek(0, SeekOrigin.End)
6 s.WriteLine("This is an example of using file handling
concepts in VB .NET.")
7 s.WriteLine("This concept is interesting.")
8 s.Close()

End Sub
End Class
Sep 30 '06 #3

khan wrote:
Hi guys

I see blue line underneat the word FileStream in the following code in
line 2.
Can any one help me to find out what am I missing
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles Button1.Click
1 Dim DestinationLoc = "c:\Stream.txt"
2 Dim FS As FileStream = New File.Open(DestinationLoc,
FileMode.OpenOrCreate, _
3 FileAccess.ReadWrite)
Take out the new. File.Open returns a FileStream object - you don't
have to create it:

Dim fs As FileStream = File.Open (DestinationLoc, _
FileMode.OpenOrCreate, FileAccess.ReadWrite)

HTH
--
Tom Shelton

Sep 30 '06 #4

khan wrote:
Hi guys

I see blue line underneat the word FileStream in the following code in
line 2.
Can any one help me to find out what am I missing
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles Button1.Click
1 Dim DestinationLoc = "c:\Stream.txt"
2 Dim FS As FileStream = New File.Open(DestinationLoc,
FileMode.OpenOrCreate, _
3 FileAccess.ReadWrite)
4 Dim s As New StreamWriter(FS)
5 s.BaseStream.Seek(0, SeekOrigin.End)
6 s.WriteLine("This is an example of using file handling
concepts in VB .NET.")
7 s.WriteLine("This concept is interesting.")
8 s.Close()

End Sub
End Class
Hmm, looking further - you could simplify this code:

Dim s As New StreamWriter ("c:\Stream.txt")
s.WriteLine ("This....")
s.WriteLine ("This con...")
s.Close ()

Of course, you might want to do some error trapping in there in real
life :)

--
Tom Shelton

Sep 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: GDL | last post by:
Hi, I'm using a FileStream as below: FileStream fs = new FileStream ( filePath, FileMode.Create, FileAccess.Write, FileShare.None
1
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
3
by: Muki Rapp | last post by:
Hi! In the example below, once the media is full, the FileSteam.WriteByte throws an exception and the code is designed to handle it. However, when the GC is invoked, it calls the Finalize of...
11
by: Dorsa | last post by:
HI, Could you please tell me the error in here. I am trying to open an XML file from a link. Response.Clear() Response.Expires = 0 Response.BufferOutput = False Response.ContentType =...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
3
by: Hugh Janus | last post by:
Hi group, I am using a TCPStream together with a FileStream to send a file across a network. Everything works fine except for one thing. Always, at the end of the file there are several lines...
6
by: bonk | last post by:
I am trying to create a stream that writes text to a file and: - automatically creates a new file once the current file exceeds a certain size - makes it possible to be used by multiple threads...
2
by: Radek | last post by:
Hi, I have the following problem with FileStream. In this line: FileStream file = new FileStream(filePath, FileMode.Append); there is an exception FileNotFoundException. But for sure path and...
8
by: Andreas Zimmermann | last post by:
Hi, we just set up a SQL Server 2008 on Windows Server 2008 (configured as file / webserver, 16 GB memory, 4 dual core processors, 6 internal disks + 15 disc ISCSI array with overall almost 3 TB...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.