[CLOSED] Dynamic FileUploadField, Response opens the file save(download) box

  1. #1

    [CLOSED] Dynamic FileUploadField, Response opens the file save(download) box

    Hi, there

    Pleas would you help me out, I have two issues regarding File Upload.

    I have a form panel where I want to add dynamic FileUploadFields but since I couldnt be able to add them dynamically on client side I wrote them statically.
    <ext:Container ID="Container3" runat="server" LabelAlign="Top" Layout="Form" ColumnWidth=".5">
                                <Items>
                                  <ext:FileUploadField ID="FileUploadField1" runat="server" FieldLabel="Attachments"  width="250" Icon="Attach" />
                                  <ext:FileUploadField ID="FileUploadField2" runat="server" width="250" Icon="Attach" />
                                  <ext:FileUploadField ID="FileUploadField3" runat="server" width="250" Icon="Attach" >                                                         
                                </Items>
    </ext:Container>
    1-) How can I add those FileUploadField dynamically. So one FileUploadField will be by default and the others to be like "add new file"

    2-) On server side I set IsUpload to true but if the user doesnt upload at least one document, the response isn't displayed instead it opens the file download box to be saved.

    Here is my server side code:

       public AjaxFormResult SaveReport(FormCollection values)
            {
                AjaxFormResult afr = new AjaxFormResult();
                Dijt di = new Dijt();          
                di.App_User_ID = Convert.ToInt32(Session["uid"].ToString());
                di.ContentDate = DateTime.Now;
    
                this.DBContext.Dijts.InsertOnSubmit(di);
    
                try{
                    this.DBContext.SubmitChanges();
                    Attachment at;
                    bool hasfile = false;
    
                    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                        if (hpf.ContentLength > 0)
                        {
                            afr.IsUpload = true;
                            hasfile = true;
                            at = new Attachment();                 
                            string savedFileName = Path.Combine(HttpContext.Server.MapPath("~/Attachments"), Path.GetFileName(hpf.FileName););
                            hpf.SaveAs(savedFileName);
                            at.Referal_ID = di.DijtID;
                            at.Attachment1 = savedFileName;
                            this.DBContext.Attachments.InsertOnSubmit(at);
    
                        }             
                          
                      
                    }
                                   
                        if (hasfile)
                        {
                            try
                            {
                                this.DBContext.SubmitChanges();
                                afr.Success = true;
                                afr.ExtraParams["feedback"] = "Raport is saved succesfully";
                            }
                            catch (Exception e)
                            {
    
                                afr.Success = false;
                                afr.ExtraParams["msg"] = e.ToString();
                                afr.ExtraParams["responseText"] = "The report is saved, but there has been an error saving your files!";
    
                            }
    
    
                        }
                        else
                        {
                            afr.Success = true;
                            afr.IsUpload = false;
                            afr.ExtraParams["feedback"] = "Raport is saved succesfully";
    
                        }
    
                   
                               
                }
                    catch(Exception e){
    
                        afr.Success = false;
                        afr.ExtraParams["msg"] = e.ToString();
                        afr.ExtraParams["responseText"] = "There has been an error on saving your report";
                    }
               
             
                return afr;
            }
    Thank you,
    Last edited by Daniil; Feb 14, 2011 at 7:17 AM. Reason: [CLOSED]
  2. #2
    Quote Originally Posted by eaglemobile View Post
    2-) On server side I set IsUpload to true but if the user doesnt upload at least one document, the response isn't displayed instead it opens the file download box to be saved.
    Hi,

    IsUpload must be 'true' in not depending on 'hpf.ContentLength > 0' condition.

    So, replace this code
    afr.IsUpload = true;
    to out of 'if' operator.
  3. #3
    Quote Originally Posted by eaglemobile View Post
    I have a form panel where I want to add dynamic FileUploadFields but since I couldnt be able to add them dynamically on client side I wrote them statically.
    <ext:Container ID="Container3" runat="server" LabelAlign="Top" Layout="Form" ColumnWidth=".5">
                                <Items>
                                  <ext:FileUploadField ID="FileUploadField1" runat="server" FieldLabel="Attachments"  width="250" Icon="Attach" />
                                  <ext:FileUploadField ID="FileUploadField2" runat="server" width="250" Icon="Attach" />
                                  <ext:FileUploadField ID="FileUploadField3" runat="server" width="250" Icon="Attach" >                                                         
                                </Items>
    </ext:Container>
    1-) How can I add those FileUploadField dynamically. So one FileUploadField will be by default and the others to be like "add new file"
    Please look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var i = 1;
        
            var addFieldUploadField = function() {
                Container1.add({
                    id      : "FileUploadField" + ++i,
                    xtype   : "fileuploadfield",
                    width   : 250,
                    iconCls : "icon-attach"
                });
                Container1.doLayout()
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Container 
            ID="Container1" 
            runat="server" 
            Layout="Form"
            LabelAlign="Top">
            <Items>
                <ext:FileUploadField 
                    ID="FileUploadField1" 
                    runat="server" 
                    FieldLabel="Attachments"
                    Width="250" 
                    Icon="Attach" />
            </Items>
        </ext:Container>
        <ext:Button runat="server" Text="Add field">
            <Listeners>
                <Click Fn="addFieldUploadField" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  4. #4

    thank you, it works

    Thank you, Daniil

    you solved both of the problems.

    You may mark the topic as solved.

Similar Threads

  1. Replies: 2
    Last Post: Aug 30, 2013, 1:48 AM
  2. [CLOSED] FileUploadField no response
    By Marcelo in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 27, 2012, 12:59 AM
  3. Replies: 1
    Last Post: Aug 30, 2010, 6:40 PM
  4. [CLOSED] FileUploadField gives a Bad Response: Missing } error
    By r_honey in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jul 26, 2010, 5:22 PM
  5. [CLOSED] "'Ext.Net.Response' is null or not an object" on store save
    By bryantharpe in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 22, 2010, 7:06 PM

Tags for this Thread

Posting Permissions