0

I want to know a proper way of saving image path to SQL server when working with ASP.net. i want to upload the image then save it to the image folder and save that path to the SQL server.I'm using SQL server 2005 & VB 2008 [using C#]

Zeus
  • 129
  • 1
  • 10

1 Answers1

0

i do not have idea about VB but in C# i can give you the logic.

//to save the images
                    if (FileUploadEventLogo.PostedFile.FileName != "")
                    {
                        string fileExt = Path.GetExtension(FileUploadEventLogo.PostedFile.FileName).ToLower();
                        if ((fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png") && FileUploadEventLogo.PostedFile.ContentLength < 1048576)
                        {
                            string strFileName = Server.MapPath("~/Images/") + EventsObject.EventID.ToString() + fileExt;
                            if (File.Exists(strFileName))
                            {
                                File.Delete(strFileName);
                            }
                            FileUploadEventLogo.SaveAs(strFileName);
                        }
                        else
                        {
                            LabelMessage.Text = "Invalid file type or file size.";
                        }
                    }

Simply you need to store your filename(strFileName in my case).extension in database.

Neha
  • 2,933
  • 3
  • 19
  • 23