xRobot
xRobot

Reputation: 26567

IsolatedStorageFileStream to base64

I am trying to convert a file to a base64 string. This is my code:

   IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(Filename, FileMode.Create, myIsolatedStorage);
   fileStream.Write(stream.GetBuffer(), 0, (int)stream.Position);

   byte[] binaryData = new Byte[fileStream.Length];
   long bytesRead = fileStream.Read(binaryData, 0, (int)fileStream.Length);
   string fileBase64 = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
   text1.Text = fileBase64.ToString();

but in text1 textblock, I get this string: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..."

Why ?

Upvotes: 0

Views: 134

Answers (1)

SLaks
SLaks

Reputation: 887375

You need to rewind fileStream before you read the data you just wrote.

Set its Position to 0.

Upvotes: 1

Related Questions