C# を使用して、ユーザーが電話で入力した URL からファイルをダウンロードしています。ファイルを IsolatedStorage に書き込んでいるときに、ファイルに書き込むバイト数が多すぎるため、これらのファイルを開くために使用されるプログラムが開きません。
デバッグすると、ビット サイズは 451,258 バイトですが、IsolatedStorage からファイルをエクスポートすると、454,656 バイトになります。残りのスペースをスペースで埋めています。このファイルサイズを調整する方法はありますか? 末尾の余分なスペースを削除して保存しますか?
私は C# と WP7 の開発に慣れていないので、私の無知を許してください。本当に助かります。
これが私のコードです:
public void readCompleteCallback(Object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
try
{
//string fileName = txtUrl.Text.Substring(txtUrl.Text.LastIndexOf("/") + 1).Trim();
string fileName = "DownloadedNZB.nzb";
bool isSpaceAvailable = IsSpaceIsAvailable(e.Result.Length);
if (isSpaceAvailable)
{
// Save mp3 to Isolated Storage
using (var isfs = new IsolatedStorageFileStream(fileName,
FileMode.CreateNew,
IsolatedStorageFile.GetUserStoreForApplication()))
{
long fileLen = e.Result.Length;
byte[] b = new byte[fileLen];
e.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
isfs.Close();
MessageBox.Show("File downloaded successfully");
}
}
else
{
MessageBox.Show("Not enough to save space available to download the file");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show(e.Error.Message);
}
}