Questions tagged [httppostedfilebase]

A class type in .NET used to assist with file uploads.

HttpPostedFileBase is a .NET class designed to make file uploads in ASP.NET projects easier.

MSDN Documentation

183 questions
49
votes
2 answers

How do you convert a HttpPostedFileBase to an Image?

I am using ASP.NET MVC and I've an action that uploads the file. The file is being uploaded properly. But I want width and height of the image. I think I need to convert the HttpPostedFileBase to Image first and then proceed. How do I do that? And…
Abdulsattar Mohammed
  • 8,916
  • 12
  • 49
  • 66
44
votes
3 answers

MVC 6 HttpPostedFileBase?

I am attempting to upload an image using MVC 6; however, I am not able to find the class HttpPostedFileBase. I have checked the GitHub and did not have any luck. Does anyone know the correct way to upload a file in MVC6?
Steven Mayer
  • 561
  • 1
  • 5
  • 18
28
votes
3 answers

MVC3 HttpPostedFileBase First Upload Gives No Data But Subsequent Do

Background of the issue. EDIT 3 I can verify that this appears to be working again in Chrome 20. Thanks! TLDR Update EDIT 2 After even further mucking about this appears to be a bug in Chrome 19. Please see…
Khepri
  • 9,297
  • 5
  • 41
  • 60
25
votes
3 answers

MVC3 How to check if HttpPostedFileBase is an image

I have a controller like this: public ActionResult Upload (int id, HttpPostedFileBase uploadFile) { .... } How can I make sure that uploadFile is an image (jpg, png etc.) I have tried with using (var bitmapImage = new Bitmap…
Henrik Stenbæk
  • 3,692
  • 5
  • 28
  • 33
24
votes
4 answers

ASP.NET MVC posted file model binding when parameter is Model

Is there any way to get posted files () to take part in model binding in ASP.NET MVC without manually looking at the request context in a custom model binder, and without creating a separate action method which only takes a…
bzlm
  • 9,198
  • 5
  • 59
  • 86
24
votes
3 answers

Mocking HttpPostedFileBase and InputStream for unit-test

I want to test the following line of code: ... Bitmap uploadedPicture = Bitmap.FromStream(model.Picture.InputStream) as Bitmap; ... Picture is a property in my model type HttpPostedFileBase. So I would like to mock a HttpPostedFileBase property for…
mosquito87
  • 3,950
  • 11
  • 39
  • 72
15
votes
1 answer

HttpPostedFileBase's relationship to HttpPostedFileWrapper

I understand the relationship between HttpPostedFileBase and HttpPostedFileWrapper, in terms of the need for both of them (i.e. in unit testing/mocking). But why, when I put a breakpoint on the return for HttpPostedFileBase, does it show it as…
Beakie
  • 1,685
  • 2
  • 16
  • 40
13
votes
4 answers

ASP MVC FIle Upload HttpPostedFileBase is Null

In my controller I have, because I wanted to be able to fill out some details about the video and actually upload it, the Video class doesn't need the actual video because it's going to be passed to another web service. public class…
Matthew Arkin
  • 4,160
  • 2
  • 22
  • 28
11
votes
2 answers

How to convert httppostedfilebase to String array

public ActionResult Import(HttpPostedFileBase currencyConversionsFile) { string filename = "CurrencyConversion Upload_" + DateTime.Now.ToString("dd-MM-yyyy") + ".csv"; string folderPath = Server.MapPath("~/Files/"); …
Gavin
  • 530
  • 1
  • 6
  • 18
10
votes
3 answers

ASP.NET MVC 4 C# HttpPostedFileBase, How do I Store File

Model public partial class Assignment { public Assignment() { this.CourseAvailables = new HashSet(); } public string AssignmentID { get; set; } public Nullable SubmissionDate { get; set;…
8
votes
6 answers

File upload in MVC when used in bootstrap modal returns null

I'm trying to upload images to my application but it always returns null. I'm unable to find the issue here. Can you help me out? Here's my code. Model [Table("Slider")] public partial class Slider : BaseModel { [Required] …
7
votes
1 answer

Returning HttpPostedFileBase to view on validation error

When I attempt to upload images to my MVC controller action and there is a validation error, I have to click through each of the buttons and find all of my files again. If I have a view that consists of
kevskree
  • 3,532
  • 3
  • 22
  • 32
6
votes
7 answers

HttpPostedFileBase.SaveAs working but no file uploaded and no exceptions

First, here is my code: private Shoe ProcessForm(Shoe shoe, HttpPostedFileBase image) { try { shoe.Slug = CMSHelper.SanitizeTitle(shoe.Name); shoe.LastModification = DateTime.Now; if ((image != null) &&…
Tommy B.
  • 3,257
  • 12
  • 54
  • 97
6
votes
3 answers

cannot save HttpPostedFileBase to session variable and use twice

Good morning - I am attempting to save an HttpPostedFileBase (which will always be a simple CSV file) to a session variable like so: [HttpPost] public ActionResult Index(HttpPostedFileBase importFile) { Session.Remove("NoteImport"); …
BueKoW
  • 916
  • 4
  • 18
  • 33
6
votes
1 answer

HttpPostedFileBase is 0 bytes on POST for only the base view model property

I have this properly posting the image and binding to the HttpPostedFileBase property on my view model, but when I put the same property in the view model's base class, it doesn't model bind the bytes. It still shows the image name, but not the…
Andrew Lundgren
  • 1,046
  • 1
  • 11
  • 18
1
2 3
12 13