[CLOSED] after upload the picture , then add picture to the htmleditor, but not work

  1. #1

    [CLOSED] after upload the picture , then add picture to the htmleditor, but not work

    <ext:FileUploadField runat="server" LabelWidth="65" Margin="4" FieldLabel="上传图片" AnchorHorizontal="100%" ButtonText="浏览" ID="fuf">
                                <DirectEvents>
                                    <Change OnEvent="ClickedUpload"></Change>
                                </DirectEvents>
                            </ext:FileUploadField>
                            <ext:HtmlEditor runat="server" ID="he_cont" AnchorVertical="-90" AnchorHorizontal="100%">
                                
                            </ext:HtmlEditor>
     protected void ClickedUpload(object o, DirectEventArgs e)
            {
    
                if (this.fuf.HasFile)
                {
                    var fname = this.fuf.PostedFile.FileName;
                    var flength = this.fuf.PostedFile.ContentLength;
    
                    Random ran = new Random();
                    string sNewName = DateTime.Now.ToString(@"yyyy-MM-dd-HH-mm-ss") + ran.Next(100, 999)
                                      + Path.GetExtension(this.fuf.PostedFile.FileName);
    
                    string strPath = HttpContext.Current.Server.MapPath("/Uploads/" + System.DateTime.Now.Year.ToString() + "/" + sNewName);
                    string path_moth = HttpContext.Current.Server.MapPath("/Uploads/" + System.DateTime.Now.Year.ToString());
                    if (!Directory.Exists(path_moth))
                    {
                        Directory.CreateDirectory(path_moth);
                    }
                    this.fuf.PostedFile.SaveAs(strPath);
                    he_cont.Text += "<img src='+"+strPath+"'/>";  // here i add image tag to the htmleditor,
                    he_cont.Render();//then rerender or render it , but the picture dose not show.
                    X.Msg.Alert("消息", "上传成功").Show();
                }
                else
                {
                    X.Msg.Alert("消息", "上传失败").Show();
                }
            }
    Last edited by Daniil; Oct 08, 2013 at 7:43 AM. Reason: [CLOSED]
  2. #2
    Hello!

    In DirectEvents you should use SetValue method instead of properties:

    he_cont.SetValue("<img src='https://examples2.ext.net/resources/css/../images/ext.net-logo.png' />");
  3. #3
    Hi @hdsoso,

    Also it looks inappropriate to use a Server.MapPath() result as an image's src, because the MapPath method returns a physical path, but the src attribute expects an URL.

Similar Threads

  1. [CLOSED] How to realize the form panel style as the attachment picture?
    By csssi_coolite in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 10:01 AM
  2. Understanding the big picture
    By meareal in forum 1.x Help
    Replies: 3
    Last Post: Dec 30, 2010, 10:20 AM
  3. Upload in the Web User Control isn't work
    By flaviodamaia in forum 1.x Help
    Replies: 0
    Last Post: Mar 12, 2010, 5:06 PM
  4. Replies: 3
    Last Post: May 25, 2009, 4:15 AM
  5. [CLOSED] Set picture in ext:Button
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Feb 27, 2009, 12:11 PM

Posting Permissions