Handle Exceptions in StoreFile of the Custom FileBrowserContentProvider

2 posts, 0 answers
  1. Omar
    Omar avatar
    1 posts
    Member since:
    Nov 2008

    Posted 12 Sep 2009 Link to this post

    Dear Support,

    I have created a custom class that inherits from FileBrowserContentProvider and have implemented all the neccesary methods.  I sometimes require to reject an uploaded file in the StoreFile method due to some business logic but was not able to figure how that could be implemented. Returning a non-empty string and throwing an exception did not work well. Since the class inherited from FileBrowserContentProvider has no access to the Page-derived class, I am not able to add an Error to the page. 

    Could you please help in directing me to a neat solution to my problem?


    Thanks in advance,

    Omtara
  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 17 Sep 2009 Link to this post

    Hello Omar,

    You can get reference to the page by using this code :

    public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments) 
        // The code that saves the file ; 
        string script = @"alert('MESSAGE');"
        Page page = HttpContext.Current.Handler as Page; 
        if (page != null
        { 
            page.ClientScript.RegisterStartupScript(page.GetType(), "ScriptKey", script, true); 
        } 
     
        return base.StoreFile(file, path, name, arguments); 

    Then you can add scripts to its script collection.

    I hope this helps.

    Sincerely yours,
    Fiko
    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