ASP.Net class to receive multiple file uploads from the browser
Questions tagged [httpfilecollection]
17 questions
10
votes
5 answers
HTTPRequest.Files.Count Never Equals Zero
I have a form on an HTML page that a user needs to use to upload a file which posts to an ASPX page. In the code behind, I want to test if a file has actually been loaded.
if (Request.Files.Count > 0)
{
DoStuff(Request.Files[0]);
}
else
{
…

kzh
- 19,810
- 13
- 73
- 97
9
votes
3 answers
resource not found instead of 413 request length exceeded
My page, when I try to upload a large file (over 10MB) displays me:
The resource you are looking for has been removed, had its name
changed, or is temporarily unavailable.
My web.config has this

Rob
- 3,556
- 2
- 34
- 53
3
votes
4 answers
Invalid Cast Exception in HttpFileCollection
I have an extension method below, but when I run this, the foreach gives me InvalidCastException and it says *
Unable to cast object of type
'System.String' to type
'System.Web.HttpPostedFile'.
Code :
public static List…

Tarik
- 79,711
- 83
- 236
- 349
2
votes
1 answer
Null reference check required to enumerate a collection inside a reflected assembly?
I'm running into a very strange behavior in C#/.NET 3.5...
I am writing a class which hooks into upload pipeline of a content management system. The CMS executes this hook via reflection.
For some unknown reason the following code fails by throws a…

Greg R
- 1,670
- 4
- 26
- 46
2
votes
2 answers
Calculate total content length of HttpFileCollection using Lambda expressions
My code has something like this:
HttpFileCollection files
Instead of looping through each file and adding up the file.ContentLength to get the total length of all content e.g.
int totalLength = 0;
for (int i = 0; i < files.Count;…

Remotec
- 10,304
- 25
- 105
- 147
1
vote
1 answer
HttpFileCollectionBase does not allow me to access any of the other MIME multipart header fields
I am constructing a MIME multipart stream that is a collection of various files/data the user has chosen for upload. I then PUT this stream to a URL using asp.net MVC 3 (though the MVC bit should be irrelevant to the question - similar applies to…

Andrew Patterson
- 1,338
- 1
- 12
- 26
1
vote
2 answers
Why is string sent down on Model and in HiddenFor, Not coming back up in form 'Resubmit' (post manual validation error)
I don't understand why a variable that I am setting on the model is coming down to the view, but not coming back up. Its 'feels' like a strange bug in HiddenFor()
I've written a simple example that reproduces the problem:
Model:
public class…

chrispepper1989
- 2,100
- 2
- 23
- 48
1
vote
0 answers
Image loss quality after upload via HttpPostedFile.SaveAs(imgPath)
I'm working in a project that doesn't use much of the .net framework and instead work with Request.Form posts.
The code that was being used to save the images (this work, but loss quality) is this…

Michel Ayres
- 5,891
- 10
- 63
- 97
0
votes
1 answer
What should i use for an HttpPostedFileBase Read Type?
I have a form where the user submits some details and a file of any kind, now since the file uploaded is of type HttpPostedFileBase, how can i arrange the reader from GetString in order to read the File Name of the uploaded file. Thanks
Error in…

Mark
- 15
- 6
0
votes
1 answer
HttpPostedFileBase ContentLength = 0 after reading
I send json file to server and want to read that twice.
[HttpPost]
public ActionResult CreateCases(string fileFormat, Guid key)
{
var file = Request.Files[0];
CheckFile(file);
Create(file);
return Json();
}
public object…

A. Gladkiy
- 3,134
- 5
- 38
- 82
0
votes
1 answer
Value of HttpFileCollectionBase Isnull on Postback
I'm curious instead of using HTTPFileWrapper, i created a model with HttpFileCollectionBase type of property.
public class UserLoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set;…

Derpuku Der
- 146
- 12
0
votes
1 answer
Why doesnt doesnt HTML input of type file not work with Ajax update panel
I have a input of type file and when i try to do a Request.files when the input is wrapped in an update panel...it always returns an empty httpfilecollection. Why???
This is the codebehind: (At HttpContext.Current.Request.Files...its always 0 for…

Sean P
- 949
- 4
- 22
- 41
0
votes
1 answer
Casting error with uploading files
I was working on my website when i noticed my foreach loop wasn't working to upload a list of files and a for loop did work. I am curious to find out why the for loop works and the foreaches loop aren't.
The error message i got was: Cannot cast…

Jamie
- 3,031
- 5
- 36
- 59
0
votes
2 answers
Video file not getting saved in the folder
I am trying to upload video file in a folder using HttpFileCollection but it appears that it is not getting saved in the folder. It is giving an error that it cannot find the path although the path is correct. This is my code
0
votes
1 answer
Converting HttpFileCollection to byte and stream the data to Image Control in asp.net
HttpFileCollection oHttpFileCollection = e.PostedFiles;
HttpPostedFile oHttpPostedFile = null;
if (e.HasFiles)
{
for (int n = 0; n < e.Count; n++)
{
oHttpPostedFile = oHttpFileCollection[n];
if…

Jack
- 151
- 1
- 4
- 21