开发者

I Get the error message while write data in file --Cannot access the disposable object .Object name :MS.internal.InternalMemorystream

开发者 https://www.devze.com 2022-12-31 04:01 出处:网络
This was the code: public static void SaveFile(Stream stream, string fileName = \"\") 开发者_如何学编程{

This was the code:

 public static void SaveFile(Stream stream, string fileName = "")
    开发者_如何学编程{
        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
        {
            IsolatedStorageFileStream fs = file.CreateFile(fileName);

            var filesize = stream.Length;
            var getContent = new byte[(int)filesize];
            stream.Read(getContent, 0, (int)filesize);
            fs.Write(getContent, 0, (int)filesize);

            fs.Close();
        }
    }


There isn't anything wrong with the code you've posted. The fault is in the code you are using to call this function. Most likely you are passing a Stream which has been disposed prematurely.

0

精彩评论

暂无评论...
验证码 换一张
取 消