Click here to Skip to main content
11,932,461 members (52,198 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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)
  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 10:46am
Edited 28-Sep-12 10: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 Wink | ;)

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
Web03 | 2.8.151126.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2015
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