'Trying to insert Image in html editor extender

I am trying to insert image into html editor extender. .

<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" EnableSanitization="false" 
    OnImageUploadComplete="HtmlEditorExtender1_ImageUploadComplete"
     TargetControlID="TextBoxBody">
    <Toolbar> 
                <ajaxToolkit:Undo />
                <ajaxToolkit:Redo />
                <ajaxToolkit:Bold />
                <ajaxToolkit:Italic />
                <ajaxToolkit:Underline />
                <ajaxToolkit:StrikeThrough />
                <ajaxToolkit:Subscript />
                <ajaxToolkit:Superscript />
                <ajaxToolkit:JustifyLeft />
                <ajaxToolkit:JustifyCenter />
                <ajaxToolkit:JustifyRight />
                <ajaxToolkit:JustifyFull />
                <ajaxToolkit:InsertOrderedList />
                <ajaxToolkit:InsertUnorderedList />
                <ajaxToolkit:CreateLink />
                <ajaxToolkit:UnLink />
                <ajaxToolkit:RemoveFormat />
                <ajaxToolkit:SelectAll />
                <ajaxToolkit:UnSelect />
                <ajaxToolkit:Delete />
                <ajaxToolkit:Cut />
                <ajaxToolkit:Copy />
                <ajaxToolkit:Paste />
                <ajaxToolkit:BackgroundColorSelector />
                <ajaxToolkit:ForeColorSelector />
                <ajaxToolkit:FontNameSelector />
                <ajaxToolkit:FontSizeSelector />
                <ajaxToolkit:Indent />
                <ajaxToolkit:Outdent />
                <ajaxToolkit:InsertHorizontalRule />
                <ajaxToolkit:HorizontalSeparator />
                <ajaxToolkit:InsertImage />
                </Toolbar>
    </ajaxToolkit:HtmlEditorExtender>

and the method on upload complete

protected void HtmlEditorExtender1_ImageUploadComplete(object sender, AjaxFileUploadEventArgs e)
    {
        string fullpath = Server.MapPath("~/Eventimg/") + e.FileName;
        var ajaxFileUpload = (AjaxFileUpload)sender;
        HtmlEditorExtender1.AjaxFileUpload.SaveAs(fullpath);
        e.PostedUrl = Page.ResolveUrl("~/Eventimg/" + e.FileName);
    }

But in file upload window i am getting this: Filename.jpg(error) uploaded 100% What am i doing wrong? Your help will be appriciated. . Thanx



Solution 1:[1]

You need to add this node in your .

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
  <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</handlers>
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="4294967295"/>
  </requestFiltering>
</security>

And add this node into your web:

<httpHandlers>
  <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</httpHandlers>

by "Will shao"

Solution 2:[2]

you are accessing the SaveAs incorrectly. Use this:

protected void HtmlEditorExtender1_ImageUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
    string fullpath = Server.MapPath("~/Eventimg/") + e.FileName;
    var ajaxFileUpload = (AjaxFileUpload)sender;
    //HtmlEditorExtender1.AjaxFileUpload.SaveAs(fullpath);
    ajaxFileUpload.SaveAs(fullpath);
    e.PostedUrl = Page.ResolveUrl("~/Eventimg/" + e.FileName);
}

Solution 3:[3]

I have found that you get an upload error with the HtmleditorExtender, if you pass QueryStrings to the page. For a long time I couldn't see what I was doing wrong. Then I changed the logic of my page - used Cookies/Session vars instead of QueryStrings - and Bingo, it worked! Strange, but true...

Solution 4:[4]

I did all these recommendations, but without success, unless I changed also a way of opening my editor page from Server.Transfer(...) to Response.Redirect(...)

I spend several hours to figure out this. Maybe somebody else find it useful :-)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thair
Solution 2 Vaibhav Garg
Solution 3 Matt
Solution 4 Noich