Does anyone know why I am getting Invalid cast exception???
For Each oFile As System.web.HttpPostedFile In Request.Files
....... etc.....
Next
I Checked that
Request.Files(0).GetType.tostring = "System.web.HttpPostedFile"
So what is the issue here??? I can just use a loop but ....
Thanks,
SA 5 4466
I don't see anything wrong with the code that you show, so I have two
questions:
1. Are you SURE the error is in the For Each line?
2. If not, what code is inside the loop?
I will admit that the only time I have ever used the HttpPostedFile class is
when uploading a file from an HtmlControls.HtmlInputFile control, but your
code looks correct based on the documentation I found. However, I have seen
situations where the errors tell you the problem is in a line other than the
one it is in (whether that is the case here, I can't say because I haven't
seen the code you have inside the loop), so one thing I might try is testing
each line individually not inside a loop by replacing oFile with
Request.Files(0). If you don't get any errors doing this, put it back inside
the loop and add an extra output line or use a debugger to determine the
value of oFile during each loop cycle. You may also want to post the code
inside the loop so that others can check that as well. Good Luck!
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP02.phx.gbl... Does anyone know why I am getting Invalid cast exception???
For Each oFile As System.web.HttpPostedFile In Request.Files
...... etc.....
Next
I Checked that
Request.Files(0).GetType.tostring = "System.web.HttpPostedFile"
So what is the issue here??? I can just use a loop but ....
Thanks,
SA
Nathan,
I am pretty sure unless the debugger is wrong.
I stepped through the debugger and it blows up at the For Each Statement and
not inside the loop
To be sure I removed everything inside the loop and still does it.
So somehow the For Each is not accepting it.
Here is the entire Code I am left with
Dim i as integer = 0
For Each oFile As System.web.HttpPostedFile In Request.Files
i += 1
Next
The error occurs at the For Each
Is there anything else I can test or do? Is this a bug.
Thanks Nathan
SA
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:eJ****************@TK2MSFTNGP04.phx.gbl... I don't see anything wrong with the code that you show, so I have two questions:
1. Are you SURE the error is in the For Each line? 2. If not, what code is inside the loop?
I will admit that the only time I have ever used the HttpPostedFile class is when uploading a file from an HtmlControls.HtmlInputFile control, but your code looks correct based on the documentation I found. However, I have seen situations where the errors tell you the problem is in a line other than the one it is in (whether that is the case here, I can't say because I haven't seen the code you have inside the loop), so one thing I might try is testing each line individually not inside a loop by replacing oFile with Request.Files(0). If you don't get any errors doing this, put it back inside the loop and add an extra output line or use a debugger to determine the value of oFile during each loop cycle. You may also want to post the code inside the loop so that others can check that as well. Good Luck! -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message news:uV**************@TK2MSFTNGP02.phx.gbl... Does anyone know why I am getting Invalid cast exception???
For Each oFile As System.web.HttpPostedFile In Request.Files
...... etc.....
Next
I Checked that
Request.Files(0).GetType.tostring = "System.web.HttpPostedFile"
So what is the issue here??? I can just use a loop but ....
Thanks,
SA
I wish I could make other suggestions, but because I have never used
System.web.HttpPostedFile for very much, I've already told you about
everything I can come up with. I would try doing some searches to see what
you can find, and see if you can come up with other scenarios involving
System.web.HttpPostedFile, sometimes having more different scenarios can
help you find even the smallest thing, and even the smallest piece of
knowledge can sometimes save you a huge amount of work (not always in
solving the problem you found it during, but you might thank yourself for
some of the time in the future). Maybe if you're lucky someone else will
post a little help, if nobody does in about a week and you still haven't
found an answer, you may want to try reposting, people sometimes ignore
postings more than about a week old if they aren't already involved in the
thread. Good Luck!
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message
news:uI**************@TK2MSFTNGP04.phx.gbl... Nathan,
I am pretty sure unless the debugger is wrong. I stepped through the debugger and it blows up at the For Each Statement and not inside the loop To be sure I removed everything inside the loop and still does it.
So somehow the For Each is not accepting it.
Here is the entire Code I am left with
Dim i as integer = 0 For Each oFile As System.web.HttpPostedFile In Request.Files i += 1 Next
The error occurs at the For Each Is there anything else I can test or do? Is this a bug.
Thanks Nathan
SA "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:eJ****************@TK2MSFTNGP04.phx.gbl...I don't see anything wrong with the code that you show, so I have two questions:
1. Are you SURE the error is in the For Each line? 2. If not, what code is inside the loop?
I will admit that the only time I have ever used the HttpPostedFile class is when uploading a file from an HtmlControls.HtmlInputFile control, but your code looks correct based on the documentation I found. However, I have seen situations where the errors tell you the problem is in a line other than the one it is in (whether that is the case here, I can't say because I haven't seen the code you have inside the loop), so one thing I might try is testing each line individually not inside a loop by replacing oFile with Request.Files(0). If you don't get any errors doing this, put it back inside the loop and add an extra output line or use a debugger to determine the value of oFile during each loop cycle. You may also want to post the code inside the loop so that others can check that as well. Good Luck! -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message news:uV**************@TK2MSFTNGP02.phx.gbl... Does anyone know why I am getting Invalid cast exception???
For Each oFile As System.web.HttpPostedFile In Request.Files
...... etc.....
Next
I Checked that
Request.Files(0).GetType.tostring = "System.web.HttpPostedFile"
So what is the issue here??? I can just use a loop but ....
Thanks,
SA
Thanks for your input,
I can work around it by not using For Each...
Thanks again,
SA
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OQ**************@TK2MSFTNGP03.phx.gbl... I wish I could make other suggestions, but because I have never used System.web.HttpPostedFile for very much, I've already told you about everything I can come up with. I would try doing some searches to see what you can find, and see if you can come up with other scenarios involving System.web.HttpPostedFile, sometimes having more different scenarios can help you find even the smallest thing, and even the smallest piece of knowledge can sometimes save you a huge amount of work (not always in solving the problem you found it during, but you might thank yourself for some of the time in the future). Maybe if you're lucky someone else will post a little help, if nobody does in about a week and you still haven't found an answer, you may want to try reposting, people sometimes ignore postings more than about a week old if they aren't already involved in the thread. Good Luck! -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message news:uI**************@TK2MSFTNGP04.phx.gbl... Nathan,
I am pretty sure unless the debugger is wrong. I stepped through the debugger and it blows up at the For Each Statement and not inside the loop To be sure I removed everything inside the loop and still does it.
So somehow the For Each is not accepting it.
Here is the entire Code I am left with
Dim i as integer = 0 For Each oFile As System.web.HttpPostedFile In Request.Files i += 1 Next
The error occurs at the For Each Is there anything else I can test or do? Is this a bug.
Thanks Nathan
SA "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:eJ****************@TK2MSFTNGP04.phx.gbl...I don't see anything wrong with the code that you show, so I have two questions:
1. Are you SURE the error is in the For Each line? 2. If not, what code is inside the loop?
I will admit that the only time I have ever used the HttpPostedFile class is when uploading a file from an HtmlControls.HtmlInputFile control, but your code looks correct based on the documentation I found. However, I have seen situations where the errors tell you the problem is in a line other than the one it is in (whether that is the case here, I can't say because I haven't seen the code you have inside the loop), so one thing I might try is testing each line individually not inside a loop by replacing oFile with Request.Files(0). If you don't get any errors doing this, put it back inside the loop and add an extra output line or use a debugger to determine the value of oFile during each loop cycle. You may also want to post the code inside the loop so that others can check that as well. Good Luck! -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"MSDN" <sq**********@hotmail.com> wrote in message news:uV**************@TK2MSFTNGP02.phx.gbl... Does anyone know why I am getting Invalid cast exception???
For Each oFile As System.web.HttpPostedFile In Request.Files
...... etc.....
Next
I Checked that
Request.Files(0).GetType.tostring = "System.web.HttpPostedFile"
So what is the issue here??? I can just use a loop but ....
Thanks,
SA
The 'bad cast' is due to the usage of Request.Files which needs to be
cast to an HttpFileCollection.
E.g.
Dim collFiles As HttpFileCollection = Request.Files
Dim objFile As HttpPostedFile
For Each objFile In collFiles
If Not objFile.FileName = "" Then
objFile.SaveAs(objFile.FileName)
End If
Next
Hope that helps... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff |
last post by:
I am using the HttpPostedFile to allow users to upload files to a
server farm. The SaveAs() saves to a shared network path
(\\SERVER\SHARE) so that no matter which web server is taking the...
|
by: |
last post by:
Hi!
It seems the HttpPostedFile object can't save a file to a
destination withing the web's structure. I want to upload
pictures from a page and store them in a subfolder to the
web folder...
|
by: terrorix |
last post by:
I want to save uploaded file to disk. I have this construction:
HttpPostedFile myFile = ((HttpRequest)Request).Files;
if (myFile != null)
{
string fn =...
|
by: Al Smith |
last post by:
Hi,
I am able to use the HttpPostedFile.SaveAs() method to upload and save a
file to the local web machine. However, I would really like to save the
file to a VirtualDirectory.
Does anyone...
|
by: NATO24 |
last post by:
Hello,
I am trying to write a sub routine that I can pass a posted (image) file
to. That routine will save the original file, then create a thumbnail
and save it. When I try to create the image...
|
by: bostonnole |
last post by:
I am getting this WinIOError "Insufficient system resources exist to
complete the requested service" when I try to execute the following
code in an ASP.NET 1.1 application uploading a very large...
|
by: Darrel |
last post by:
I'm grabbing a file from a file upload form field. This is a
'system.web.httppostedfile'
I would like to modify the image (Cropping/scaling) using
system.drawing.image.
Is there anyway to go...
|
by: Ralph Watermann |
last post by:
Hi,
we upload an Excel-file via a FileUpload-Control into an HttpPostedFile
object.
Now we want to access the contained data directly without saving it to a
temp file. Is this possible?
So...
|
by: Shaikh shahnawaz |
last post by:
Hi,
I have implement multiple file uploading progress bar with the help of flash and .net file is upload on my local machine but not working with server it's give error while uploading image on...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |