Q:

Asyncupload control of AjaxControlToolkit

I am using asyncupload control of AjaxControlToolkit and I want to check the file to be uploding is already exists or
not on server.
How we can do this?
Please help me out.
<!-- Client side code for control-->
<script>
 function uploadError(sender, args) {
        //document.getElementById('lblStatus').innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }

    function StartUpload(sender, args) {                
        var nodeSelectedText = document.getElementById('<%=lblFileLocation1.ClientID%>').innerHTML;

        if (nodeSelectedText == "") {            
            $("#msgMissingSelection").dialog("open");
            args.set_cancel(true);
        }
        else {
            return true;
        }        
    }

        function UploadComplete(sender, args) {     
            var hdnFieldVal = document.getElementById('<%=hdnField.ClientID%>');

            if(hdnFieldVal.value == "1")
{
            $("#msgFileUploadExists").dialog("open");        
}
            else
            {
            $("#msgFileUpload").dialog("open");        
}
        }
</script>

<!-- Control Code in aspx-->
<tr>
                            <td></td>
                            <td> 
                                <cc1:AsyncFileUpload ID="FileUpload2"  Width="265px" runat="server" 
                                    OnClientUploadError="uploadError" 
                                    OnClientUploadStarted="StartUpload"
                                    OnClientUploadComplete="UploadComplete"
                                    CompleteBackColor="Lime" UploaderStyle="Modern" 
                                    ErrorBackColor="Red" 
                                    ThrobberID="Throbber" 
                                    onuploadedcomplete="AsyncFileUpload1_UploadedComplete" 
                                    UploadingBackColor="#66CCFF" />

                                    <asp:Label ID="Throbber" runat="server" Style="display: none">
                                        <img src="../../images/indicator.gif"  align="absmiddle" alt="loading" />
                                    </asp:Label> 
                                    <asp:HiddenField ID="hdnField" runat="server" value=""/>
                            </td>
                        </tr>

//.CS Code for ayncupload control
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
string filePath="C:\Documents\temp.txt"
         if(File.Exists(filePath))
{
hdnField.value="1";//Not able to access this value
}
}

Thanks!!

A:

you just need to set your hidden field value at client side script.
See I have made little changes in your server side code:
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        string filePath = "C:\\Documents\\temp.txt";
        string hiddenValue = "0";
        if (File.Exists(filePath))
        {
            hiddenValue = "1";
        }
        //This script will set required value for hidden field.
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "SetHiddenField", String.Format("top.$get('{0}').value = '{1}'", hdnField.ClientID, hiddenValue), true);
    }

Make changes in your script location as follow:
 <ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" />

       <script>
 function uploadError(sender, args) {
        //document.getElementById('lblStatus').innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
    }

    function StartUpload(sender, args) {                
        var nodeSelectedText = document.getElementById('<%=lblFileLocation1.ClientID%>').innerHTML;

        if (nodeSelectedText == "") {            
            $("#msgMissingSelection").dialog("open");
            args.set_cancel(true);
        }
        else {
            return true;
        }        
    }

        function UploadComplete(sender, args) {     
            var hdnFieldVal = document.getElementById('<%=hdnField.ClientID%>');

            if(hdnFieldVal.value == "1")
            {
              $("#msgFileUploadExists").dialog("open");        
            }
            else
            {
              $("#msgFileUpload").dialog("open");        
            }
        }
</script>

