Tag: 分块

如何在块中使用File.ReadAllBytes

我正在使用此代码 string location1 = textBox2.Text; byte[] bytes = File.ReadAllBytes(location1); string text = (Convert.ToBase64String(bytes)); richTextBox1.Text = text; 但是当我使用一个太大的文件时,我会遇到内存exception。 我想在块中使用File.ReadAllBytes 。 我见过这样的代码 System.IO.FileStream fs = new System.IO.FileStream(textBox2.Text, System.IO.FileMode.Open); byte[] buf = new byte[BUF_SIZE]; int bytesRead; // Read the file one kilobyte at a time. do { bytesRead = fs.Read(buf, 0, BUF_SIZE); // ‘buf’ contains the last 1024 […]

以块的forms下载文件(Windows Phone)

在我的应用程序中,我可以从网上下载一些媒体文件。 通常我使用WebClient.OpenReadCompleted方法下载,解密并将文件保存到IsolatedStorage。 它运作良好,看起来像这样: private void downloadedSong_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e, SomeOtherValues someOtherValues) // delegate, uses additional values { // Some preparations try { if (e.Result != null) { using (isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()) { // working with the gained stream, decryption // saving the decrypted file to isolatedStorage isolatedStorageFileStream = new IsolatedStorageFileStream(“SomeFileNameHere”, FileMode.OpenOrCreate, isolatedStorageFile); // and use […]