locked
AjaxFileUpload Tool. Set upload target dynamically RRS feed

  • Question

  • User-797201019 posted

    I'm trying to set the upload path dynamically. But the upload tool keeps taking the first path specified to the dropdownlist. It doesnt matter if I have the dropdownlist in a seperate update panel and tell the dropdownlist to stay on the selected index if there is a postback. How would I get the upload tool to use the value selected in the dropdownlist and not first value. Below is my code:

     protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                    foldList.SelectedIndex = foldList.SelectedIndex;
                }
                else
                {
                    Allfiles();
                }
            }
            public void Allfiles()
            {
                foldList.Items.Clear();
                String RootFold = ConfigurationSettings.AppSettings["RootPath"];
                string[] foldNames = Directory.GetDirectories(RootFold, "*", SearchOption.AllDirectories);
    
                foreach (string i in foldNames)
                {
                    if (i.Contains(".") == true)
                    {
                        //DO NOTHING
                    }
                    else
                    {
                        foldList.Items.Add(i);
                    }
                }
            }
     
    
    public void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
            {
                try
                {
                   
                   filePath = foldList.SelectedItem.Text.ToString() + @"\" + e.FileName;
                    AjaxFileUpload1.SaveAs(filepaths);
                    MessageBox.Show(filepaths);
    
                }
                catch (Exception error)
                {
                    Label1.Text=(error.Message);
                }
            }
    Here Is the HTML I have tried putting the 2 different controls in seperate update panels and that hasnt worked either

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>

    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div align="center">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <ContentTemplate>
    <asp:DropDownList ID="foldList" runat="server"
    onselectedindexchanged="foldList_SelectedIndexChanged" AutoPostBack="True">
    </asp:DropDownList>
    </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" >
    <ContentTemplate>
    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
    onuploadcomplete="AjaxFileUpload1_UploadComplete"
    onuploadstart="AjaxFileUpload1_UploadStart" />
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
    </body>
    </html>

    Wednesday, April 23, 2014 4:16 AM

Answers

  • User-417640953 posted

    Hi garethcarver,

    Thank you post the issue to our forum.

    As known that, when we click the upload button of AjaxFileUpload, it will create an ajax post request to server.

    It would not post any other select or input values to server side, so the dropdownlist selected index just the default value not you selected on the client side.

    In other word, AjaxFileUpload1_UploadComplete method cannot get any postback data, it just a server side method used to handler uploaded file.

    Thus, we cannot set the folder path dynamically of AjaxFileUpload control.

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 24, 2014 2:00 AM

All replies

  • User555306248 posted

    can you move AjaxFileUpload outside of Updatepanle and try

    Thursday, April 24, 2014 12:01 AM
  • User-417640953 posted

    Hi garethcarver,

    Thank you post the issue to our forum.

    As known that, when we click the upload button of AjaxFileUpload, it will create an ajax post request to server.

    It would not post any other select or input values to server side, so the dropdownlist selected index just the default value not you selected on the client side.

    In other word, AjaxFileUpload1_UploadComplete method cannot get any postback data, it just a server side method used to handler uploaded file.

    Thus, we cannot set the folder path dynamically of AjaxFileUpload control.

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 24, 2014 2:00 AM