C#简单文件上传器无法输出流

时间:2012-09-15 15:01:11

标签: c# windows-phone-7 file-upload webclient isolatedstorage

我正试图在我的WP7应用程序中直接从IsolatedStorage实现文件上传。我基于这个优秀的例子http://gregdoesit.com/2009/10/file-upload-in-silverlight-a-simple-solution/

我用来开始UploadChunk()调用链的代码是:

public void uploadPackage(String packagePath)
    {
        string[] pathSplit = packagePath.Split('\\');
        _fileName = pathSplit[1];
        IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream packageFile = isf.OpenFile(packagePath,     System.IO.FileMode.Open, FileAccess.Read);

        _bytesUploaded = 0;
        _bytesTotal = packageFile.Length;
        _data = packageFile;

        try
        {
            UploadFileChunk();
        }
        catch (Exception ex)
        {
        }
    }

一切似乎都运行良好,直到wc_OpenWriteCompleted事件发生。它实现如下:

if (e.Error == null)
        {
            object[] objArr = e.UserState as object[];
            byte[] fileContent = objArr[0] as byte[];    // NullReferenceException
            int bytesRead = Convert.ToInt32(objArr[1]);
            Stream outputStream = e.Result;
            outputStream.Write(fileContent, 0, bytesRead);
            outputStream.Close();
        }

objArr,第3行无法被赋值,而e.UserState具有非空值。这会导致第4行出现NullReferenceException,objArr为null。

可能导致什么问题?我真的很喜欢这个,我真的很感激你的任何帮助。

0 个答案:

没有答案