Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 18th, 2008, 06:16 AM
Authorized User
Join Date: Jul 2008
Location: new delhi, delhi, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav gupta
Default prob. related to image upload

hi every one
i am using this code to upload two images or you can upload no of images from this code .

string filepath = "C:\\Uploads";
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
HttpPostedFile userPostedFile = uploadedFiles[i];
userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName ));
but whan i want to load only one image then it shows error:
Could not find a part of the path 'C:\Uploads\'.when i try to search that what is going on.then i came to know that if i select 1 image only then the value of uploadedFiles 2 that why loop run two times and show error .
my prob is why it takes 2 when i select 1 image only.

plz let me know.

thanks ...gaurav

  #2 (permalink)  
Old July 18th, 2008, 07:59 AM
Friend of Wrox
Join Date: Nov 2007
Location: Central Florida, USA.
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts

If i understand you right... no matter if you put two files or one file your loop still tries to upload two? if that's the case then you need to check that the HttpPostedFile has a file. If it does then upload it otherwise do nothing:

     string filepath = "C:\\Uploads";
     HttpFileCollection uploadedFiles = Request.Files;
     for (int i = 0; i <= uploadedFiles.Count - 1; i++) {
         HttpPostedFile userPostedFile = uploadedFiles(i);
         if (userpostedfile.hasfile) {
             userPostedFile.SaveAs(filepath + "\\" + System.IO.Path.GetFileName(userPostedFile.FileName ));

Jason Hall
  #3 (permalink)  
Old July 21st, 2008, 07:50 AM
Authorized User
Join Date: Jul 2008
Location: new delhi, delhi, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav gupta



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload image-create & save thumbnail-display image angshujit ASP.NET 2.0 Professional 6 July 11th, 2013 10:34 PM
how to upload image? vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 3 June 3rd, 2008 02:53 AM
Upload image phuc2583 Classic ASP Basics 1 January 17th, 2008 08:48 AM
Image Upload spbharti Pro PHP 3 February 3rd, 2006 08:20 AM
Image upload cutesneakers PHP How-To 2 January 5th, 2005 08:00 AM

All times are GMT -4. The time now is 01:32 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.