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

[Solved] Server-side Upload Method on Editor File Manager?

5 Answers 223 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ryan C
Top achievements
Rank 1
Ryan C asked on 23 Oct 2009, 11:04 AM
I want to know if there is away to do some validation before the user uploads the files, in an Editor. Reason is I want to limit the uploading to a particular IP.


                    <telerik:RadEditor ID="txtContent" runat="server" Width="100%">  
                        <ImageManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files"  /> 
                        <MediaManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" /> 
                        <FlashManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" /> 
                        <TemplateManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" /> 
                        <DocumentManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" /> 
                    </telerik:RadEditor> 

5 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 28 Oct 2009, 03:41 PM
Hi Ryan C,

You can do this check in the ItemCommand event of the RadFileExplorer control which is used in the editor's dialogs. For your convenience I have attached a demo to this thread.

I hope this helps.

Greetings,
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.
0
Ryan C
Top achievements
Rank 1
answered on 02 Nov 2009, 09:03 AM

Thanks for the suggestion but I could not understand exactly how to imply the provided code to my project. However with further research I found out I can use the OnFileUpload event. However I get the followign error:

No overload for 'txtContent_FileUpload' matches delegate 'Telerik.Web.UI.EditorDialogEventHandler'


public bool txtContent_FileUpload(object sender, string fileName, EditorFileTypes type) 
  { 
    bool continueUpload = false
 
      string userAddress = Context.Request.UserHostAddress; 
      if (userAddress != "127.0.0.1") 
      {// do nothing  
        continueUpload = false;// cancel upload 
      } 
      else 
{
        continueUpload = true
      } 

      return continueUpload; 
 
  } 

0
Fiko
Telerik team
answered on 05 Nov 2009, 10:45 AM
Hello Ryan,

This error is expected because the FileUpload's handler does not accepts 3 parameters. In your case this event should looks like this :

public bool txtContent_FileUpload(object sender, string fileName)
{
    string userAddress = Context.Request.UserHostAddress;
    if (userAddress != "127.0.0.1")
    {// do nothing
        if (!this.Page.ClientScript.IsClientScriptBlockRegistered("RestrictedIP"))
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "RestrictedIP", "alert('Your IP:" + userAddress + " is restricted');", true);
        }
        return false;// Cancel upload
    }
    // else
    return true;
}

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.
0
Ryan C
Top achievements
Rank 1
answered on 05 Nov 2009, 11:22 AM
Thanks that worked. However I did not get any alert box when the upload is restricted. Do I have to add anything to the client side?
0
Fiko
Telerik team
answered on 10 Nov 2009, 03:55 PM
Hello Ryan,

I am not quite sure what is causing the problem in your case. Could you please open a new support ticket and send me a project that reproduces the problem? As an alternative you could paste your code (both aspx and C#) to the forum. Once I have a better view over your code I will do my best to help.

I am looking forward to hearing from you.

Regards,
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
Editor
Asked by
Ryan C
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Ryan C
Top achievements
Rank 1
Share this question
or