Link to home
Start Free TrialLog in
Avatar of gregasm
gregasm

asked on

TextWriter not writing everything

I have a webservice that takes a base64 encoded string and converts it to xml, and then writes it out to a file.

Here is the code that creates the base64 string:

MemoryStream memStream = new MemoryStream();
                        TextWriter writer = new StreamWriter(memStream);
                        TextReader reader = new StreamReader(this.txtPath.Text);
                        writer.Write(reader.ReadToEnd());
                        writer.Close();
                        param = Convert.ToBase64String(memStream.ToArray();


And here is the code that reads the base64 string back to text (xml):

public string Add(string Base64Binary)
            {
                  try
                  {
                        MemoryStream memStream = new MemoryStream(Convert.FromBase64String(Base64Binary));
                        TextReader reader = new StreamReader(memStream);
                        string temp = reader.ReadToEnd();
                        FileStream strm = new FileStream(Server.MapPath(Guid.NewGuid().ToString() + ".xml"), FileMode.Create, FileAccess.Write);
                        TextWriter writer = new StreamWriter(strm);
                        writer.Write(temp);
                        strm.Close();
                        return "Ack";
                  }

The thing is: The file, when I open it, seems to be truncated! Have any of you guys run into this problem before, and know what's going on? Thanks!
Avatar of dfiala13
dfiala13

Need to flush the writer. It's onoly writing the first 1024 characters.

TextWriter writer = new StreamWriter(strm);
 writer.Write(temp);
writer.Flush();
 strm.Close();


ASKER CERTIFIED SOLUTION
Avatar of dfiala13
dfiala13

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gregasm

ASKER

I am gonna try this first thing tomorrow morning.. THANKS MAN! I have a good feeling about this one hehehe
You should. I actually tested the code for once. ;)
Avatar of gregasm

ASKER

Thank you! I knew it was some "mundane detail" (from office space). =]]
Proper use of "flair" will often overcome those "mundane details".
Avatar of gregasm

ASKER

Hahah, dfiala13 you're a cool guy. =]]
Avatar of gregasm

ASKER

and smart! 153003 pts in one month! ! dang. you've got lots of flair. =]
blush, blush