TPG
TPG

Reputation: 3201

ASP.Net image become unable to open after Upload with AJAX HTMLEditor

I implemented a functions in AJAXControlToolkit to allow upload of image, but once I uploaded the image, it become not able to open (originally it open without problem in my PC). Note that however, some of the files uploaded without problem.

Below is the upload code

protected void tbxContent_HtmlEditorExtender_ImageUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
            try
            {
                string storage = @"/storage/";
                string filename = DateTime.Now.Ticks.ToString() + e.FileName.Substring(e.FileName.IndexOf('.'));

                if (!Directory.Exists(Server.MapPath(storage)))
                {
                    Directory.CreateDirectory(Server.MapPath(storage));
                }

                // Save your File
                (sender as AjaxControlToolkit.AjaxFileUpload).SaveAs(Server.MapPath(storage + filename));

                // Tells the HtmlEditorExtender where the file is otherwise it will render as: <img src="" />
                e.PostedUrl = storage + filename;
            }
            catch (Exception ex)
            {

            }
        }

When I click on the image file at the server, I got the error as below. enter image description here

Updated 1: Seems like all the image details gone after uploaded to server, previously it exists my local PC. enter image description here

Upvotes: 0

Views: 179

Answers (0)

Related Questions