Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a FileUpload control "FcustPicUpload".
By this customer can upload their pictures and this will save in database.

There are 2 question i want to ask..

1. I want to save those pictures in Upload/ customer/"customerID" folder where customerID folder will create automatically depends on the customerID.. How to do it?

2. How to Get the full Path of those pictures/files. I want to send those FullPath name in Database.


I am using ASP.NET 2012 and SQL SERVER 2008

Thanks in Advance
Posted
Comments
ZurdoDev 9-Jan-14 7:48am    
When you are saving the file you tell it where to save. Then store that path in the db.

1 solution

C#
string folder = HttpContext.Current.Server.MapPath("~/Upload/customer/" + customerID);
System.IO.Directory.CreateDirectory(folder);
string imageFile = HttpContext.Current.Server.MapPath("~/Upload/customer/1/photo.jpg");
FileUpload1.SaveAs(imageFile);
 
Share this answer
 
v3
Comments
SumitChandra 11-Jan-14 1:43am    
string imageFile = HttpContext.Current.Server.MapPath(folder+FileName);

can i use this line instead of
string imageFile = HttpContext.Current.Server.MapPath("~/Upload/customer/1/photo.jpg");
adriancs 11-Jan-14 1:47am    
It is up to you to decide, you can Server.MapPath("~/" + "anything anywhere anypath and any name");.
SumitChandra 11-Jan-14 2:28am    
try
{
string folder = HttpContext.Current.Server.MapPath("~/Upload/customer/" + txtEmail.Text);
System.IO.Directory.CreateDirectory(folder);

string fileName = Path.GetFileName(fileUploadCustomer1.FileName);
fileUploadCustomer1.SaveAs(Server.MapPath(folder + fileName));
lblUpload.Text = "Upload status: File uploaded!";

}
catch
{
lblUpload.Text = "Upload status: The file could not be uploaded!";
}



NOT WORKING
adriancs 11-Jan-14 2:35am    
You code has no error. The error is coming from the invalid values. There are so many values in your code, I don't know which of them have error.

Check the following values are valid or not:
- txtEmail.Text
- fileName
- folder + fileName

Try catch the error like this and find out the error.

try
{
// ... perform your task
}
catch (Exception ex)
{
Response.Write(ex.ToString().Replace("\r\n", "<br />");
}
SumitChandra 13-Jan-14 0:35am    
Yes everything in perfect but at runtime its not uploading

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