Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
Below is my code to upload images. My problem is while uploading in internet error is occurring as Access Denied: I know this is occurring since permission is not provided, Therefore, please help me how to provide permission using coding to allow upload images to particular folder. Thanks!

C#
protected void btnSubmit_Click(object sender, EventArgs e)
    {


        if (FileUploadControl.HasFile)
        {
            try
            {
                if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                {
                    if (FileUploadControl.PostedFile.ContentLength < 5242881)
                    {
                        string filename = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("images/profile/") + filename);
                        StatusLabel.Text = "Upload status: File uploaded!";
                    }
                    else
                        StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                }
                else
                    StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }



        }
    }
Posted
Updated 14-Mar-21 8:16am

Hi abdulsafran,

Please kindly ask your hosting provider to give full permission for you. The error above access denied indicate that you dont have permission enough. Good luck. :)
 
Share this answer
 
I fear, by using this code you can't upload your files to the server. You need the ftp details of the server and then you can use the ftp credentials in code and upload your files.

There is an article on this, you can go through it Upload file to server using FTP[^]
 
Share this answer
 
Comments
abdulsafran 18-Dec-13 10:36am    
Hi Tapas, Thanks for your response, I'll check this and get back to you.
abdulsafran 20-Dec-13 11:25am    
Provided code is not enough for me since I want to get full path of the upload file such as when user upload their image, it has a path in the hard drive, that full path I need. Please advise.
Sai Natuva 25-Oct-18 0:29am    
Can any one guide me how to host images in godaddy directory using asp.net Web api directory from base 64 format to image using ftp or is their any better option
The error occur may due to the fact that u not have write permission to server , contact your hosting service provider to provide write permission.
 
Share this answer
 
 
Share this answer
 
v2
Comments
OriginalGriff 14-Mar-21 15:18pm    
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 8 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more!
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900