Unable to cast object of type 'Telerik.Web.UI.PostedFile' to type 'Telerik.Web.UI.UploadedFile'.

Thread is closed for posting
4 posts, 0 answers
  1. vishesh kumar
    vishesh kumar avatar
    24 posts
    Member since:
    Sep 2009

    Posted 27 Jan 2010 Link to this post

    Hi,

    I am creating a project (business objects ) with a reference to the .20 assembly. When i try to iterate over the files in the radupload.uploaded files collection, I get this exception

    Unable to cast object of type 'Telerik.Web.UI.PostedFile' to type 'Telerik.Web.UI.UploadedFile'.

    I am not able to fix it.

    Then i tried addding the reference to the .35 assembly of Telerik.web.ui and then i got a compile time error stating

    Error 271 Assembly "XXX" uses 'Telerik.Web.UI, Version=2009.2.826.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' which has a higher version than referenced assembly 'Telerik.Web.UI, Version=2009.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4'

    What should i do?
    Help!!

  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 27 Jan 2010 Link to this post

    Hi vishesh kumar,

    Can you please paste here the code that you use to iterate over the uploaded files?

    All the best,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. vishesh kumar
    vishesh kumar avatar
    24 posts
    Member since:
    Sep 2009

    Posted 27 Jan 2010 Link to this post

    public bool ValidateFile()
            {
                bool isFileValidated = false;
                
                foreach (UploadedFile file in this.files)
                {
                    if (true == this.extensions.Contains(file.GetExtension()) &&
                        true == this.mimeTypes.Contains(file.ContentType) &&
                    file.ContentLength <  this.contentLength*1000000)
                    {
                        isFileValidated = true;
                    }
                    else
                    {
                        isFileValidated = false;
                        break;
                    }
                }
                return isFileValidated;
            }
    Here this.files is the uploadedfilecollection
  4. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 29 Jan 2010 Link to this post

    Hello vishesh kumar,

    This code should not throw any errors since the UploadedFilesCollection returns UploadedFile. I tried to reproduce the problem on my side, however no avail, I managed to successfully iterate over the uploaded files collection. Can you give us more details regarding your scenario? Are you sure that this.files returns UploadedFilesCollection? How do you populate that collection?

    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top