I am using the file selector and filelist controls. When a user adds a file, I am calling the "OnClientFileAdded" method. In that method I am doing some checking to see what kind of file type it is. What I would like to do, is remove the file from the list AND from the input (textbox with the browse button) if the file isn't of a certain extension (I can explain why if you wish, but its just some funky business requirements).
The code I am using is below. Note the bolded text. This is where I need to remove the file. The file is removed from the list, however it still appears in the input textbox and if I click "Upload" it uploads the file I wanted to delete.
Thanks for your help.
function addFile(file) {
if (file.extension != 'pdf') {
//let the user know that non PDF docs cannot be merged.
alert("You may only upload PDF documents to have them automatically merged.");
//get the file selector
var fileUpload = kw.get('<%= fsSelector1.ClientID %>');
var files = fileUpload.get_Files();
if (files.length == 1)
{
//first file, don't show the file selector since the files is not .pdf format
document.getElementById('<%= dvFileSelector.ClientID %>').style.display = 'none';
//Disable the flatten option.
<%= ClientID %>_showHideFlatten(false);
}
else
{
//since this isn't the first file and its a non-pdf, remove it from the list.
fileUpload.remove_File(file.get_Id);
}
}
else
{
var showFlattener = document.getElementById('<%= hfShowFlattener.ClientID %>');
if (showFlattener.value == "1")
{
//if its a pdf, make sure the flatten option is shown if applicable
<%= ClientID %>_showHideFlatten(true);
}
}
//don't show the Form Editor or my library links since a file has already been chosen.
document.getElementById('<%= dvEditorLink1.ClientID %>').style.display = 'none';
document.getElementById('<%= dvMyLibrary.ClientID %>').style.display = 'none';
}