hi
Hari Try this
Listing 1: Add FileUpload Control
<asp:FileUpload ID="fileDocument" runat="server"></asp:FileUpload>
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click"
Text="Upload"></asp:Button>
Listing 2: OnClientClick
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload"
Width="64px" OnClientClick="return CheckForTestFile();" />
Listing 3: JS Filter function
<script language="javascript">
//Trim the input text
function Trim(input)
{
var lre = /^\s*/;
var rre = /\s*$/;
input = input.replace(lre, "");
input = input.replace(rre, "");
return input;
}
// filter the files before Uploading for text file only
function CheckForTestFile()
{
var file = document.getElementById('<%=fileDocument.ClientID%>');
var fileName=file.value;
//Checking for file browsed or not
if (Trim(fileName) =='' )
{
alert("Please select a file to upload!!!");
file.focus();
return false;
}
//Setting the extension array for diff. type of text files
var extArray = new Array(".txt", ".doc", ".rtf", ".pdf", ".sxw", ".odt",
".stw", ".html", ".htm", ".sdw", ".vor");
//getting the file name
while (fileName.indexOf("\\") != -1)
fileName = fileName.slice(fileName.indexOf("\\") + 1);
//Getting the file extension
var ext = fileName.slice(fileName.indexOf(".")).toLowerCase();
//matching extension with our given extensions.
for (var i = 0; i < extArray.length; i++)
{
if (extArray[i] == ext)
{
return true;
}
}
alert("Please only upload files that end in types: "
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
file.focus();
return false;
}
</script>
refer this url
http://aspalliance.com/1614_Adding_Filter_Action_to_FileUpload_Control_of_ASPNET_20.all
Mark as Answer if its helpful to you
Kumaraspcode2009@gmail.com
Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator