Incorrect file length - how to solve this ?

4 posts, 1 answers
  1. Vasssek
    Vasssek avatar
    190 posts
    Member since:
    Aug 2010

    Posted 02 Feb 2011 Link to this post

    Hello,

    I wonder if somebody knows how to get real file size (length) of the uploaded file. In my application I use this method:

    protected void fileUploaded(object sender, FileUploadedEventArgs e)
            {
                try
                {
                    if (RadAsyncUpload1.UploadedFiles.Count > 0)
                    {
                        if (targetPersonalTmpFolder.Exists.Equals(false)) targetPersonalTmpFolder.Create();

                        foreach (UploadedFile uploadedFile in RadAsyncUpload1.UploadedFiles)
                        {
                            //UploadedFileInfo uploadedFileInfo = new UploadedFileInfo(uploadedFile);

                            string fullPath = Path.Combine(targetPersonalTmpFolder.ToString(), uploadedFile.GetName());
                            uploadedFile.SaveAs(fullPath, true);
                           
                            TmpFiles_List.Add(new UplodedFileData()
                            {
                                FileName = uploadedFile.GetName(),
                                FullFileName = targetPersonalTmpFolder.ToString() + @"\" + uploadedFile.GetName(),
                                //FileContentLength = Math.Round(uploadedFile.InputStream.Length / 1024d, 0).ToString() + " KB"
                                FileContentLength = Math.Round(uploadedFile.ContentLength / 1024d, 0).ToString() + " KB"
                            });
                           
                        }

                        BindFiles();
                        BindTmpFiles();
                    }
                }
                catch (Exception ex)
                {
                    //Pravdepodobne bol stlaceny klaves F5 refresh stranky...
                    ReinitializeForm();
                }
            }

    --------------------------------------------------------------------------------------------
    The problem is that property uploadedFile.ContentLength doesn't return real length of the file. I've found that this uploadedFile.InputStream.Length returns correct file size, but when I tried to use it, then this error appeared: The process cannot access the file because it is being used by another process...

    Something similar is described here: http://www.telerik.com/community/forums/aspnet-ajax/async-upload/temporary-files-locked-after-upload.aspx

    For further information you can check the attachment.

    Please help me to solve this issue...

    Best regards Vasssek

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 03 Feb 2011 Link to this post

    Hello Vasssek,

    Indeed such issue exist. We are ought to fix it for the upcoming Q1 release, meanwhile you could use the following workaround:

    void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            using (var stream = e.File.InputStream)
            {
                var length = stream.Length;
            }
        }

    Greetings,
    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.
  3. Vasssek
    Vasssek avatar
    190 posts
    Member since:
    Aug 2010

    Posted 07 Feb 2011 Link to this post

    Hello Genady,

    your workaround didn't work. For further info please check attachment. Maybe it's because I've decided to use the last official release version 2010.3.1317.35.

    Instead of that, I've created a new fileinfo object and get real file length:

    string fullPath = Path.Combine(targetPersonalTmpFolder.ToString(), uploadedFile.GetName());
    uploadedFile.SaveAs(fullPath, true);
      
    FileInfo fileInfo = new FileInfo(fullPath);                       
      
    TmpFiles_List.Add(new UplodedFileData()
    {
         FileName = uploadedFile.GetName(),
         FullFileName = targetPersonalTmpFolder.ToString() + @"\" + uploadedFile.GetName(),
         //FileContentLength = Math.Round(uploadedFile.InputStream.Length / 1024d, 0).ToString() + " KB"
         //FileContentLength = Math.Round(uploadedFile.ContentLength / 1024d, 0).ToString() + " KB"
         FileContentLength = Math.Round(fileInfo.Length / 1024d, 0).ToString() + " KB"
    });

    Anyway, thank you for your advice...

    Best regards

    Vasssek
  4. Answer
    Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 10 Feb 2011 Link to this post

    Hello Vasssek,

    Thank you for sharing this solution with the community. We will address the issue in the Q1 release. I've updated your telerik points for the feedback.

    All the best,
    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