andres
andres

Reputation: 115

how to validate only files are pdf?

I need to create a regular expression in a FileUpload, that only allow pdf files

<asp:RegularExpressionValidator runat="server" ID="valUpTest" ControlToValidate="FileUpload1"
                           ErrorMessage="Files Only (.pdf)" ValidationExpression="?" />

Upvotes: 0

Views: 1781

Answers (3)

BerggreenDK
BerggreenDK

Reputation: 5004

You cant trust client side validation alone nor file extension. You need to open the uploaded binary data and check if the headers of the file is "correct".

Upvotes: 1

The Mask
The Mask

Reputation: 17427

Try this regular expression:

\.pdf$

Upvotes: 0

Bueller
Bueller

Reputation: 2344

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx

There is an example about 3/4 of the way down the page how to do this the ASP way.

Upvotes: 1

Related Questions