1

I want to get the size of file in isolated storage as bytes. also need to read that file as block of 1024 bytes each. How can I do that?

Nelson T Joseph
  • 2,683
  • 8
  • 39
  • 56

1 Answers1

1
public static IsolatedStorageFileStream OpenFile(string filePath)
    {
        IsolatedStorageFileStream fileStream = null;

        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!store.FileExists(filePath))
            {
                return fileStream;
            }
            else
            {
                fileStream = store.OpenFile(filePath, FileMode.Open,     FileAccess.ReadWrite, FileShare.ReadWrite);
        }
        return fileStream;
    }

void ReadFile()
 {
    using (var streamReader = OpenFile(filePath))
    {
      using (BinaryReader reader = new BinaryReader(streamReader))
      {
         byte[] buffer = new byte[1024];
         int fileLen = (int)reader.BaseStream.Length;
         int readCount=0;
         while (fileLen > 0)
         {
            readCount = reader.Read(buffer, 0, buffer.Length);
            fileLen = fileLen - readCount;
            //Do what ever with buffer
         }
       }}}
nucleons
  • 742
  • 5
  • 21
  • I am writing the buffer to an outputstream(OpenWriteCompletedEventArgs Result stream of webclient). If the file is very big, there is an error occurs. Out of memory exception . How to overcome this error? – Nelson T Joseph Sep 13 '12 at 10:19