Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Please can anyone help me with this error? I am trying to store an image path in database but I am having this exception "could not find a part of the path", the database is a local host. I wanted to store the image in Image folder and store the path in the database. here is the code.

C#
property.PropetyType = DropDownListControlPropertyType.SelectedValue;
               property.Area = TextBoxControlArea.Text;
               property.Tenure=TextBoxControlTenure.Text;
               property.TitleType = DropDownListControlTitleType.SelectedValue;
               property.LandTitleType = TextBoxControlLandTitleType.Text;
               property.BuiltUp = TextBox1ControlBuiltUp.Text;
               property.UnitType = TextBoxControlUnitType.Text;
               property.Price = Convert.ToDouble(TextBoxControlPrice.Text);
               property.PricePerSqf = TextBoxControlPricePerSqf.Text;
               property.BedRooms = TextBoxControlBedrooms.Text;
               property.Occupancy = TextBoxControlOccupancy.Text;
               property.Furnishing = TextBoxControlFurnishing.Text;
               property.Date = DateTime.Now;
               property.Address = TextBoxControlAddress.Text;
               fileName = Path.GetFileName(FileUploadControlPhoto.PostedFile.FileName);
               FileUploadControlPhoto.SaveAs(Server.MapPath("Images/"+ fileName));
               property.Photo = fileName;
               property.PropertyDetails = TextBox1CotrolPropertyDetails.Text;

               property.AddData(property.PropetyType, property.Area, TextBoxControlTenure.Text, property.TitleType, property.LandTitleType, property.BuiltUp, property.UnitType, property.Price, property.PricePerSqf, property.BedRooms, property.Occupancy, property.Furnishing, property.Date, property.Address, property.Photo, property.PropertyDetails);
Posted
Comments
Richard C Bishop 19-Dec-13 14:13pm    
You need to check the filename and path you are using. Debug the application and see what the actual value is.
Murugan Kolanji 19-Dec-13 14:18pm    
Is the file is saved into your local server path?

Is the below code succeed?

FileUploadControlPhoto.SaveAs(Server.MapPath("Images/"+ fileName));
Member 10215709 19-Dec-13 14:30pm    
the exception is at this line of code. once it reaches to this line, it is giving the error.
FileUploadControlPhoto.SaveAs(Server.MapPath("Images/"+ fileName));
Murugan Kolanji 19-Dec-13 15:09pm    
Try this instead of:

FileUploadControlPhoto.SaveAs(Server.MapPath("~/Images/"+ fileName));
Member 10215709 19-Dec-13 15:15pm    
I tried it is not giving the error but the actual image is not stored in the Image folder while the path is stored in database. The folder is still empty.

1 solution

Probably, this is because the web page is not in the root folder - and your folder uses a relative path, which is always relative to teh current web page.
Try changing this:
C#
FileUploadControlPhoto.SaveAs(Server.MapPath("Images/"+ fileName));
To this:
C#
FileUploadControlPhoto.SaveAs(Server.MapPath("~/Images/"+ fileName));
 
Share this answer
 
Comments
Member 10215709 19-Dec-13 14:43pm    
I used this
FileUploadControlPhoto.SaveAs(Server.MapPath("~/Images/"+ fileName));
instead of this:
FileUploadControlPhoto.SaveAs(Server.MapPath("Images/"+ fileName));

It is not giving the error but the actual image is not stored in the Image folder. The folder is still empty.
OriginalGriff 19-Dec-13 14:55pm    
Where are you doing this? Did you check the FileUploadControlPhoto.HasFile property?
Member 10215709 19-Dec-13 15:10pm    
I checked that one the file is there, but not stored in the folder, but path is stored in database.
OriginalGriff 19-Dec-13 15:39pm    
No, did you check that the upload control had a file ready to save?
Member 10215709 19-Dec-13 15:46pm    
Now it is working thank you so much

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