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

Handle Exceptions in StoreFile of the Custom FileBrowserContentProvider

1 Answer 103 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Omar
Top achievements
Rank 2
Omar asked on 12 Sep 2009, 12:04 PM
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

1 Answer, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 17 Sep 2009, 06:45 AM
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.
Tags
FileExplorer
Asked by
Omar
Top achievements
Rank 2
Answers by
Fiko
Telerik team
Share this question
or