By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Empty path is not legal exception while updating images in C# (winforms).

P: 15
Hi Everyone,

I am developing 1 desktop application to my friend office,in that application i can store multiple images and i can retrieve the information for the same..My issue here is after retrieving the information when i click on update button I'm getting runtime exception i.e (Empty path is not legal exception)..

Here is the code which I wrote under updatebutton method:

Expand|Select|Wrap|Line Numbers
  1. public partial class CustomerDetails : Form
  2.     {
  3.  
  4.         string imageloc = "";
  5.         string imageloc1 = "";
  6.         string imageloc2 = "";
  7.         string imageloc3 = "";
  8.         string imageloc4= " ";
  9.    public static Byte[] Imagesave(string imagelocation)
  10.         {
  11.             byte[] img = null;
  12.            /*Empty path is not legal error*/ FileStream fs = new FileStream(imagelocation, FileMode.Open, FileAccess.Read);
  13.             BinaryReader br = new BinaryReader(fs);
  14.             img = br.ReadBytes((int)fs.Length);
  15.             fs.Close();
  16.             br.Close();
  17.             return img;
  18.         }
  19. private void btnupdateinfo_Click(object sender, EventArgs e)
  20.         {
  21.  
  22.             string scn = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString;
  23.             using (SqlConnection cn = new SqlConnection(scn))
  24.             {
  25.                 using (SqlCommand cmd = new SqlCommand("SP_UpdateInfo", cn))
  26.                 {
  27.                     try
  28.                     {
  29.  
  30.  
  31.                         cmd.CommandType = CommandType.StoredProcedure;
  32.  
  33.                         cmd.Parameters.AddWithValue("@Hp_Number", tbhpnum.Text);
  34.                         cmd.Parameters.AddWithValue("@Customer_Name", tbcusnam.Text);
  35.                         cmd.Parameters.AddWithValue("@Customer_Contact_Number", tbcusmblno.Text);
  36.                         cmd.Parameters.AddWithValue("@Guarantor_Name", tbguanam.Text);
  37.                         cmd.Parameters.AddWithValue("@Guarantor_Contact_Number", tbguamblno.Text);
  38.                         cmd.Parameters.AddWithValue("@Hp_Date", DateTime.Parse(tbhpdat.Text));
  39.                         cmd.Parameters.AddWithValue("@Customer_Address", tbcusadd.Text);
  40.                         cmd.Parameters.AddWithValue("@Vehicle", tbveh.SelectedItem.ToString());
  41.                         cmd.Parameters.AddWithValue("@Vehicle_Model", tbvehmod.SelectedItem.ToString());
  42.                         cmd.Parameters.AddWithValue("@Vehicle_Number", tbvehnum.Text);
  43.                         cmd.Parameters.AddWithValue("@Chasis_Number", tbchanum.Text);
  44.                         cmd.Parameters.AddWithValue("@Engine_Number", tbengnum.Text);
  45.                         cmd.Parameters.AddWithValue("@FC_Date", DateTime.Parse(tbfcdat.Text));
  46.                         cmd.Parameters.AddWithValue("@Insurance_Date", DateTime.Parse(tbinsdat.Text));
  47.                         cmd.Parameters.AddWithValue("@Insurance_Amount",                               Convert.ToInt32(tbinsamt.Text));
  48.                         cmd.Parameters.AddWithValue("@Paid_Amount", Convert.ToInt32(tbpaiamt.Text));
  49.                         cmd.Parameters.AddWithValue("@Paid_Date", DateTime.Parse(tbpaidat.Text));
  50.                         cmd.Parameters.AddWithValue("@Vehicle_Pic",Imagesave(imageloc));
  51.                         cmd.Parameters.AddWithValue("@Customer_Pic", Imagesave(imageloc1));
  52.                         cmd.Parameters.AddWithValue("@Guarantor_Pic", Imagesave(imageloc2));
  53.                         cmd.Parameters.AddWithValue("@Documents_Pic", Imagesave(imageloc3));
  54.                         cmd.Parameters.AddWithValue("@Insurance_Pic", Imagesave(imageloc4));
  55.  
  56.                         if (cn.State != ConnectionState.Open)
  57.                             cn.Open();
  58.  
  59.                         int count = cmd.ExecuteNonQuery();
  60.                         if (count == 1)
  61.                         {
  62.                             MessageBox.Show(count.ToString() + "Customer(s) Record(s) has Updated                     Successfully .", "Succes", MessageBoxButtons.OK);
  63.                         }
  64.  
  65.  
  66.                     }
  67.  
  68.                     catch (SqlException ex)
  69.                     {
  70.                         MessageBox.Show(ex.ToString());
  71.  
  72.                     }
  73.                     finally
  74.                     {
  75.                         if (cn.State == ConnectionState.Open)
  76.                             cn.Close();
  77.                     }
  78.                 }
  79.             }
  80.  
  81.         }
Attached Images
File Type: jpg error.jpg (37.6 KB, 119 views)
Feb 23 '15 #1
Share this Question
Share on Google+
3 Replies


P: 4
please set your image location should be save
Mar 24 '15 #2

P: 15
I'm directly saving all the images into Database,in that case I didn't set path instead of that converting all the images into byte format before saving into database.
Mar 25 '15 #3

Rabbit
Expert Mod 10K+
P: 12,356
You're trying to open a file using a blank string on that line.
Mar 25 '15 #4

Post your reply

Sign in to post your reply or Sign up for a free account.