How to upload and save image from kentico widget?

Muhammad Kaleem asked on February 28, 2019 17:59

i'm new to kentico mvc, i want to know about how can i create a widget to image upload in page builder? can anyone share a sample code for image widget? any help will be highly appreciated... thanks

Correct Answer

vasu yerramsetti answered on March 1, 2019 07:35

Please go through the DancingGoat MVC project with the following files for Image Widget.

\Kentico12\DancingGoatMvc\Controllers\Widgets\ImageWidgetController.cs
\DancingGoatMvc\Models\Widgets\ImageWidget\ImageWidgetViewModel.cs
\DancingGoatMvc\Views\Shared\Widgets\_ImageWidget.cshtml

Reference URL - https://docs.kentico.com/k12/developing-websites/page-builder-development/developing-widgets-in-mvc

Hope this helps.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Muhammad Kaleem answered on March 1, 2019 07:53 (last edited on March 1, 2019 07:53)

thanks vasu yerramsetti, i have copy each and every thing of dancing goat image widget to an empty kentico mvc project but unable to upload image, during uploading it gives exception. Is kentico widget works on free edition license?

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on March 2, 2019 08:07

hi vasu, can you help me? ImageUploadEditorController gives error in AddUnsortedAttachment() method

if (!(Request.Files[requestFileName] is HttpPostedFileWrapper file)) { return Guid.Empty; }

        var directoryPath = EnsureUploadDirectory();
        var imagePath = GetTempFilePath(directoryPath, file);
        byte[] data = new byte[file.ContentLength];
        file.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
        file.InputStream.Read(data, 0, file.ContentLength);
        When create object of HttpPostedFileWrapper as file it gives error
0 votesVote for this answer Mark as a Correct answer

Petline developer answered on April 24, 2019 21:17

Hi Muhammad,

Was wondering if you were able to fix the issue with the image upload. I have the same issue, copied all the relevant files from DancingGoat, when I use the bannerWidget, all I get is the text widget but don't see the Image upload option.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.