Click here to Skip to main content
16,015,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
upload image to store database with image path
Posted
Comments
[no name] 15-Jul-11 3:07am    
If you are lazy enough to put your question in bits and pieces, how do you expect others to answer?

Take namespace system.data.sqlclient

and make a folder as Album


and on click event of button write this code:

C#
string path = "";
        string ab = "";
         if (FileUpload1.HasFile)
            {
                string SFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                int fileAppent = 0;
                while (File.Exists(Server.MapPath("~/Album/" + SFileName)))
                {
                    fileAppent++;
                    SFileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName)
                        + fileAppent.ToString() + Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
                }
                path = Server.MapPath("~/Album/" + SFileName);
                FileUpload1.PostedFile.SaveAs(path);
                ab = "~/Album/" + SFileName;
        SqlCommand cmd = new SqlCommand("insert into ImageURL(ImageUrl)values(@ImageUrl)", con);
        cmd.Parameters.AddWithValue("@ImageUrl",ab);
           con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
         }
 
Share this answer
 
 
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