Click here to Skip to main content
12,997,210 members (75,102 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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)
  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;

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
Updated 28-Sep-12 9:49am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use Path.GetFilename()[^].

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2017
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