How to get a byte array from the uploaded file?

Last post 04-16-2009, 10:52 AM by cutechat. 2 replies.
Sort Posts: Previous Next
  •  04-16-2009, 9:06 AM 51157

    How to get a byte array from the uploaded file?

    CuteWebUI.MvcUploadFile file = uploader.GetUploadedFile(fileguid);
     
    if (file != null)
    {
     
    // instead of moving the file to a temp-folder, how can I get access to the bytes, like:
    // byte[] theFile = new byte[file.ContentLength];
    // theFile = file.ToArray();

    file.MoveTo("~/UploaderTemp/" + file.FileName);

    processedfiles.Add(file.FileName);

    }

    Filed under:
  •  04-16-2009, 9:28 AM 51158 in reply to 51157

    Re: How to get a byte array from the uploaded file?

    Hi all,
     
    I solved the problem
     
    using (Stream uploadedStream = file.OpenStream())
    {

       byte[] theFile = new byte[uploadedStream.Length];
       uploadedStream.Read(theFile, 0, (int)uploadedStream.Length);
    }

    just a mising doc for MvcUploadFile

    Best regards
    Catwiesl
  •  04-16-2009, 10:52 AM 51161 in reply to 51158

    Re: How to get a byte array from the uploaded file?

    Hi,
     
    That is a new class of Uploader 3.0 , and we are prepairing the documents for it.
     
    You can also check this method to get the temp path (which name is different from file.FileName)
     
    string fullpath=file.GetTempFilePath();
     
    (if you will not use none-file-system uploader provider.)
     
    (AjaxUploader supports custom provider to store the temporary files, and we already have a database example)
     
    Regards,
    Terry
View as RSS news feed in XML