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

MemoryStream instance length is 0 after stream has been written

I'm trying to write new stream from string and i can't figure out why my
memory stream
instance is null after i have writen to it with stream writer.

Here is an example.

MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter();

writer.Write ("my string");

at this point i check what does my stream contain and it says .Length = 0
so why is that ? How can it be 0 if i've just written to it with writer ?
Nov 29 '06 #1
2 4807
I'm trying to write new stream from string and i can't figure out why
my
memory stream
instance is null after i have writen to it with stream writer.
Here is an example.

MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter();
writer.Write ("my string");

at this point i check what does my stream contain and it says .Length
= 0 so why is that ? How can it be 0 if i've just written to it with
writer ?
Call writer.Flush();

Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 29 '06 #2

Mikus Sleiners wrote:
I'm trying to write new stream from string and i can't figure out why my
memory stream
instance is null after i have writen to it with stream writer.

Here is an example.

MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter();

writer.Write ("my string");

at this point i check what does my stream contain and it says .Length = 0
so why is that ? How can it be 0 if i've just written to it with writer ?
How does your StreamWriter know to write to your stream? You have not
specified the stream that the stream writer should write to. Also, you
should use the using pattern if possible:

MemoryStream stream = new MemoryStream();
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write("my string");
}

Notice that the memory stream was passed into the constructor of the
stream writer.

Chris

Nov 29 '06 #3

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

Similar topics

7
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in memory. I'd like to create some simple methods to...
1
by: xmlguy | last post by:
PREVIOUS BACKGROUND POST: I am trying to reuse a Memory Stream for loading and transforming the xml it contains Basically I have defined following interfaces: Class Render {
7
by: Donovan | last post by:
I can't believe this is causing me as much difficulty as it is, but I have an Infragistics UltraTreeview control that I want to persist whatever the user has in the tree. It has a method SaveAsXml...
2
by: Brian Mitchell | last post by:
Hello, I am using a MemoryStream to serialize a class but when I use the GetBuffer method it returns exactly 1024 bytes even though the stream is only 675 bytes. If I look at the...
13
by: Don | last post by:
When I run the following code, the MemoryStream's Position is always set to 762 instead of 0, which is what I would expect: Dim bmp As Image Dim ms As MemoryStream bmp = New...
5
by: Naamat | last post by:
Hello, I am the sample FPSEPublish (http://blog.baeke.info/blog/_archives/2005/3/3/393158.html) code to upload a document to Sharepoint (WSS). This works perfectly for samll documents. ...
10
by: Asaf | last post by:
Hi, I am trying to Compress & Decompress a DataSet. When running this code I am receiving the error: System.Xml.XmlException was unhandled Message="Root element is missing."...
7
by: Maciej Oszutowski | last post by:
Hi, I'm going to port my PE manipulation library (written in C) to managed c++ class library. I would like to have opportunity to read content not only from files, but also from memory, for...
1
by: MSwanston | last post by:
Hi I need some help with saving retreiving data from the cache, and how best to structure my code. FYI am working in VS2005/under .NET2 Framework. Ok, we have a series of reports that get run via...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.