Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
This is my code for save image and image name in database
C#
OpenFileDialog fop = new OpenFileDialog();
//fop.InitialDirectory = @"C:\Users\ODYSSEY\Downloads\Documents\Panorama\Resources\";
fop.Filter = "[JPG,JPEG]|*.jpg";
if (fop.ShowDialog() == DialogResult.OK)
{
  FileStream FS = new FileStream(@fop.FileName, FileMode.Open, FileAccess.Read);
  byte[] img = new byte[FS.Length];
  FS.Read(img, 0, Convert.ToInt32(FS.Length));
  if (con.State == ConnectionState.Closed)
    con.Open();
  SqlCommand cmd = new SqlCommand("SaveImage", con);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;
  cmd.Parameters.Add("@imgname", SqlDbType.VarChar).Value = @fop.FileName;
  cmd.ExecuteNonQuery();

It store image as binary data and imageName as full path for example c:\Documents\Images\Rose.jpgi>I want to save imageName as "Rose.jpg" in database. How can i do this?
Posted
Updated 28-Sep-12 9:49am
v3

Here[^] you'll find your answer ;)
 
Share this answer
 
Use Path.GetFilename()[^].

/ravi
 
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