Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.....
I want to prepare a page. In this user can upload an image.

I used file upload control. This is working properly on local system but it not working on my website...

please send a specific code for this..
plz help me...
Posted
Comments
Prerak Patel 3-May-12 2:39am    
Share your code.
Rahul Rajat Singh 3-May-12 2:47am    
Before that I will ask whether you are running a single server or multiple servers because that is important when it comes to storing files on server.

you need to give relative path to run this on server.


myFile.PostedFile.SaveAs(server.mappath("Images\myphoto.png");
 
Share this answer
 
C#
protected void UploadButton_Click(object sender, EventArgs e)
     {
         if(FileUploadControl.HasFile)
           {
     try
     {
         string filename = Path.GetFileName(FileUploadControl.FileName);
         FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
         StatusLabel.Text = "Upload status: File uploaded!";
     }
     catch (Exception ex)
     {
         StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
     }
         }


     }
 
Share this answer
 
Please check the solution provided below. Make sure that you have already set the required settings:

C#
protected void btnUploadPic_Click(object sender, EventArgs e)
{
    if(PicFileUploadCtrl.HasFile)
        {
        try
        {
            string strFileName = Path.GetFileName(PicFileUploadCtrl.FileName); // Get the name of the selected Pic
            PicFileUploadCtrl.SaveAs(Server.MapPath("~/") + strFileName );  // Save the selected Pic on the server
            lblStatus.Text = "Pic uploaded successfully!!!";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Error while uploading the Pic.";         

        }

}
 
Share this answer
 
Change you path with these line of code it will work fine ....

if (Directory.Exists(Server.MapPath("~/UploadedFiles")))
{
Some code here

}
else

{
Directory.CreateDirectory(Server.MapPath("~/UploadedFiles"));


}
 
Share this answer
 

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