Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:44:02+00:00 2026-05-27T13:44:02+00:00

According to the MSDN documentation, by default the FileExtensionsAttribute (.NET 4.5) should allow me

  • 0

According to the MSDN documentation, by default the FileExtensionsAttribute (.NET 4.5) should allow me to only upload only jpg,jpeg,gif and png files – which is what I want.

I tried uploading a jpg without the attribute, it works. Great. Then
I added the attribute to my view model..

[FileExtensions(ErrorMessage = "Please specify a valid image file (.jpg, .jpeg, .gif or .png)")]
public HttpPostedFileBase ImageFile { get; set; }

No joy. The verification fails and the ErrorMessage is shown. On top of that there doesn’t seem to be a way to specify any allowed custom file extensions.
I ended up extending the FileExtensionsAttribute and using my own verification logic, which works as expected. But why doesn’t this way work?

Will post the entire controller and view if required. I used this example as a basis for the uploading logic, but using the DataAnnotations.FileExtensionsAttribute instead of Microsoft.Web.Mvc.FileExtensions.. How do I upload images in ASP.NET MVC?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:44:02+00:00Added an answer on May 27, 2026 at 1:44 pm

    Use the Extensions property to set them. Although according to the documentation

    The file name extensions, or the default file extensions (“.png”,
    “.jpg”, “.jpeg”, and “.gif”) if the property is not set.

    You can set it just like you did the ErrorMessage. The more likely issue is that it doesn’t know how to assess whether the HttpPostedFileBase has the right extension. You’ll need to use the one from the MVC framework or create your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQLCMD uses windows authentication by default. According to the MSDN documentation , you can
According to MSDN in .Net DateTimeFormat.MonthName should contain exactly 13 elements with 12 element
According the the MSDN documentation, the following code should output '5' to the console
According to the MSDN documentation , transactional NTFS doesn't seem to allow one to
According to MSDN Documentation for partial classes : Partial methods are implicitly private So
According to the documentation of the == operator in MSDN , For predefined value
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
According to the MSDN documentation for the WindowStartupLocation Property : Setting CenterScreen causes a
According to the MSDN documentation , configSource is supported on Windows Server 2003 SP2.
I'm using ICommandText::GetCommandText method. According to the MSDN documentation ( http://msdn.microsoft.com/en-us/library/ms709825(v=VS.85).aspx ) I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.