Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
This is my code for save image and image name in database
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 28-Sep-12 9:46am
Edited 28-Sep-12 9:49am
JF201553.2K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use Path.GetFilename()[^].
 
/ravi
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here[^] you'll find your answer Wink | ;)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100