Read file data from AsyncUpload?

4 posts, 0 answers
  1. John
    John avatar
    41 posts
    Member since:
    Jun 2008

    Posted 07 Dec 2010 Link to this post

    Hi all:

    I am working with this example:

    http://demos.telerik.com/aspnet-ajax/upload/examples/async/webmail/defaultcs.aspx?product=asyncupload

    However I do not understand how to read the file data from the uploaded files. I need to read the files into a byte array. Here is the code:

    PopulateUploadedFilesList();
    if (UploadedFiles != null)
    {
      AttachmentRepeater.DataSource = UploadedFiles;
      AttachmentRepeater.DataBind();
      for (int i = 0; i<UploadedFiles.Count; i++)
      {
           #region get file content
           // Open a file and read the contents into a byte array.
           FileStream stream = File.OpenRead(UploadedFiles[i].FileName);
           byte[] byteData = new byte[stream.Length];
           stream.Read(byteData, 0, byteData.Length);
           stream.Close();
           // Encode the data using base64.
           string encodedData = System.Convert.ToBase64String(byteData);
         }
      }

    Any and all help is greatly appreciated.

    John.
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 09 Dec 2010 Link to this post

    Hello John,

    Here is how you can read an uploaded file into a byte array:

    void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            using (Stream str = e.File.InputStream)
            {
                byte[] content = new byte[str.Length];
                str.Read(content, 0, content.Length);
            }
        }

    I hope that this helps.

    Regards,
    Genady Sergeev
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. John
    John avatar
    41 posts
    Member since:
    Jun 2008

    Posted 09 Dec 2010 Link to this post

    Thanks for your reply. Is there a way to hide the text box and just have the "Select" button visible?
  4. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 14 Dec 2010 Link to this post

    Hello John,

    Yes, this can be achieved with the following CSS:

    .RadUpload input.ruFakeInput
            {
                display: none;
            }


    Regards,
    Genady Sergeev
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top