Click here to Skip to main content
15,905,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have upload only doc files .. how to do so using asp.net fileupload control
Posted

1 solution

if you want to validate from the client side use the following:

JavaScript
function ValidatePDFupload(Source, flag)
{
var pathTextBox = document.getElementById('txtBoxFilePath');
var FileUploadPath = pathTextBox.value;


var FileExtension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();


if (FileExtension == "pdf")
{
flag.IsValid = true;  // Allow to upload PDF File
}
else
{
flag.IsValid = false; // Don't allow to upload pdf file
}


}


if you want to validate from the server side, use the following:

C#
string p = @"C:\Users\linton\Documents\Sample.pdf";

        string e = Path.GetExtension(p);
        if (e == ".pdf")
        {
            Console.WriteLine(e);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900