p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 6th, 2006, 03:21 AM
Friend of Wrox
Points: 970, Level: 12
Points: 970, Level: 12 Points: 970, Level: 12 Points: 970, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2006
Location: Bangalore, Karnataka, India.
Posts: 232
Thanks: 0
Thanked 1 Time in 1 Post
Default FileUpload Control

hi to all
i am trying to upload image file. inspite of no error in code it is going to exception and displaying error message of exception i am providing my code below

================================================
protected void btnUpLoad_Click(object sender, EventArgs e)
    {
        Boolean fileOK = false;
        String path = Server.MapPath("~/UploadedImages/");
        if (FileUpload1.HasFile)
        {
            String fileExtension =
                System.IO.Path.GetExtension(FileUpload1.FileName). ToLower();
            String[] allowedExtensions =
                { ".gif", ".png", ".jpeg", ".jpg" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileOK = true;
                }
            }
        }

        if (fileOK)
        {
            try
            {
                string uploadpath = path + FileUpload1.FileName;
                FileUpload1.PostedFile.SaveAs(uploadpath);
                Label1.Text = "File uploaded!";
            }
            catch (Exception ex)
            {
                Label1.Text = "File could not be uploaded.";
            }
        }
        else
        {
            Label1.Text = "Cannot accept files of this type.";
        }
    }
================================================== ========
the above code in written under the button click called btnload:
it goes to exception ex and displays label1 message.
plz tell if any other setting or code is required

reply

thanks......
__________________
thanks......
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old December 6th, 2006, 03:33 AM
Imar's Avatar
Wrox Author
Points: 33,170, Level: 79
Points: 33,170, Level: 79 Points: 33,170, Level: 79 Points: 33,170, Level: 79
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,161
Thanks: 7
Thanked 188 Times in 186 Posts
Default

Hi there,

Please don't cross-post. Posting your message once is more than enough.

That said, temporarily remove the Catch block so the application throws a real error. Then you can what the exact error message is, instead of "File could not be uploaded".

Maybe it's a security problem where the webserver account isn't allowed to write to your UploadedImages folder.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old December 6th, 2006, 04:03 AM
Friend of Wrox
Points: 970, Level: 12
Points: 970, Level: 12 Points: 970, Level: 12 Points: 970, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2006
Location: Bangalore, Karnataka, India.
Posts: 232
Thanks: 0
Thanked 1 Time in 1 Post
Default

thanks i get the error u were right it was access problem to folder.
Thanks!


thanks......
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access denied error when using FileUpload Control mii2029 ASP.NET 3.5 Basics 0 October 25th, 2008 06:45 PM
Problem to implement CSSClas on fileupload control azizur123 ASP.NET 2.0 Professional 1 October 13th, 2008 10:50 AM
fileupload control in formview insert item templat rakuntal General .NET 10 August 8th, 2007 01:55 AM
FileUpload control aliirfan84 ASP.NET 2.0 Professional 1 June 2nd, 2007 04:37 PM
FileUpload control -- file size detection ekwong ASP.NET 2.0 Basics 3 November 7th, 2006 06:32 PM



All times are GMT -4. The time now is 10:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc