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

[Solved] OnFileUpload Handler

9 Answers 336 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Scott Smith
Top achievements
Rank 1
Scott Smith asked on 28 Oct 2007, 05:21 AM
Hi...Where is the "OnFileUpload" handler in Editor Prometheus?  I have a routine that reduces theimages uploaded that fired in the old editor when I went to upload an image in the image manager.

Thx

Scott

9 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 29 Oct 2007, 11:10 AM
Hi Scott,

RadEditor Prometheus does not expose such event. If you need to execute custom code when a file is uploaded, you could inherit a class from Telerik.Web.UI.Widgets.FileSystemContentProvider, override the StoreFile method and execute your custom routine there. Please, let me know if you need a sample and we will provide you with one.

All the best,
Valeri Hristov (Senior Developer, MCSD)
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott Smith
Top achievements
Rank 1
answered on 29 Oct 2007, 12:11 PM
Hi Valeri:

Yes, could you provide a sample.

Thanks.

Scott
0
Valeri Hristov
Telerik team
answered on 29 Oct 2007, 12:24 PM
Hello Scott,

Please, find attached the requested sample. Let me know how it goes.

All the best,
Valeri Hristov (Senior Developer, MCSD)
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott Smith
Top achievements
Rank 1
answered on 27 Dec 2007, 04:07 PM
Hi Valeri:

I did it just like the example you sent and I am getting the following error:

Error 41 No overload for method 'FileSystemContentProvider' takes '0' arguments

Below is the relevant code.

Thanks.

Scott

public class CustomContentProvider : Telerik.Web.UI.Widgets.FileSystemContentProvider

{

public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)

{

string targetFullPath = Path.Combine(path, name);

if (File.Exists(targetFullPath))

{

File.Delete(targetFullPath);

}

//Instead of saving the image file, you could execute

// your routine for decreasing its dimensions.

//file.SaveAs(Context.Server.MapPath(targetFullPath));

if (targetFullPath.ToUpper().EndsWith(".JPG") || targetFullPath.ToUpper().EndsWith(".GIF") || targetFullPath.ToUpper().EndsWith(".PNG") || targetFullPath.ToUpper().EndsWith(".BMP"))

{

//string originalImageLocation = Server.MapPath(fileName);

Bitmap bmp = CreateThumb(targetFullPath, 500, 500);

//Delete the original bitmap

File.Delete(targetFullPath);

//Save new bitmap using the same name

bmp.Save(targetFullPath, System.Drawing.Imaging.

ImageFormat.Jpeg);

bmp.Dispose();

}

//You have to return the full path of the saved file here

return targetFullPath;

}

}

protected void Page_Load(object sender, System.EventArgs e)

{

txtEditor.ImageManager.ContentProviderTypeName =

typeof(CustomContentProvider).AssemblyQualifiedName;

EditorSetup();

}

 

0
Rumen
Telerik team
answered on 03 Jan 2008, 08:43 AM
Hello Scott,

You can download an example demonstrating how to create a DBFileBrowserContentProvider with RadEditor "Prometheus" from here: DBFileBrowserContentProvider.zip. Please, test it and let me know if you still experience the problem.

The example should be tested on IIS, but not on Cassini (the web development server of Visual Studio).


Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott Smith
Top achievements
Rank 1
answered on 01 Feb 2008, 02:11 AM
Hi Rumen:

It appears to use this I will need to rewrite all of the methods in the FileBrowserContentProvider class.  Is that true?  All I really need to do is override the StoreFile method with my routine that resizes the image.  Do you have an example that is file system-based and not database-based, because based upon the DB sample I will need to rewrite the View Files methods too even though the native ones work fine.

Thanks.

Scott
0
Lini
Telerik team
answered on 04 Feb 2008, 04:41 PM
Hi Scott,

Yes, it is possible to override only the StoreFile method. However, your provider needs to need to inherit from the existing editor file system provider instead of the generic file browser provider. Here is some sample code:

public class CustomEditorFileProvider : Telerik.Web.UI.Widgets.FileSystemContentProvider  
{  
    public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)  
    {  
        string fileName = base.StoreFile(file, path, name, arguments);  
        //create thumbnail here  
 
        //  
        return fileName;  
    }  

All the best,
Lini
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Lini
Telerik team
answered on 04 Feb 2008, 05:03 PM

A colleague noted that the above code will not compile since you also need to define a constructor. I am posting the updated snippet here:

public class CustomEditorFileProvider : Telerik.Web.UI.Widgets.FileSystemContentProvider  
{  
    public CustomEditorFileProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)  
        : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)  
    {  
    }  
    public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)  
    {  
        string fileName = base.StoreFile(file, path, name, arguments);  
        //create thumbnail here  
 
        //  
        return fileName;  
    }  


Lini
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott Smith
Top achievements
Rank 1
answered on 04 Feb 2008, 06:36 PM
Worked like a charm.  Thanks Lini.

Scott
Tags
Editor
Asked by
Scott Smith
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Scott Smith
Top achievements
Rank 1
Rumen
Telerik team
Lini
Telerik team
Share this question
or