This is a migrated thread and some comments may be shown as answers.

Incorrect file length - how to solve this ?

3 Answers 285 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Vasssek
Top achievements
Rank 1
Vasssek asked on 02 Feb 2011, 12:21 PM
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

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 03 Feb 2011, 03:07 PM
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.
0
Vasssek
Top achievements
Rank 1
answered on 07 Feb 2011, 09:24 PM
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
0
Accepted
Genady Sergeev
Telerik team
answered on 10 Feb 2011, 05:40 PM
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.
Tags
AsyncUpload
Asked by
Vasssek
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Vasssek
Top achievements
Rank 1
Share this question
or