473,387 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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, 192 views)
Feb 23 '15 #1
3 2625
please set your image location should be save
Mar 24 '15 #2
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
12,516 Expert Mod 8TB
You're trying to open a file using a blank string on that line.
Mar 25 '15 #4

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

Similar topics

1
by: Matthias Ludwig | last post by:
I'm trying to create a directory on the web server with a vb.net code: .... Dim dirName As String = "w:\filepath\images" If Not Directory.Exists(dirName) Then...
2
by: billrdio | last post by:
I am trying to make a JavaScript animation of real-time images - i.e. images that will periodically change on the server. The problem I am having is that the JavaScript animation I have created is...
1
by: Magnus Blomberg | last post by:
Hello! When loading a path with spaces to Image.ImageURL from an SQL database, the picture is not shown. The path in the Image becomes Xxxxxx%2520xxx and is not working. In another application...
1
by: Alan Silver | last post by:
Hello, I have the following line of code in a script... litMsg.Text = Server.MapPath("/"); where litMsg is an ASP.Net Literal control. When I try and run this page, I get the error ... ...
0
by: Steve Amey | last post by:
Hi all I am having a problem when I am updating my database. I am using a strong DS and the PK column is an Identity column, but when I am udating my database I am getting the exception 'Column...
4
by: Chas Stapleton | last post by:
I have recently uninstalled VB5 and installed vb.net 2002. In working on an application, I attempted to add a picturebox and add an image... I immediately received an "empty path name is not...
6
by: delusion7 | last post by:
I'm not really sure I'm going about my problem the right way or not. What I want to to is have a save button, bring up the save dialog, and save a report from reportViewer(.rdlc) in .pdf format. ...
0
by: JR | last post by:
System exception messages in VS2005 are given in the local language. Sometimes it is nice, but often it is quite inconvenient - try looking up MSDN or Google with a localized message! So, after...
2
by: ranjith konnoju | last post by:
hi, i am getting an exception while populating the data in the datagrid. am getting the values into datatable and binding it to the datagrid but it is not displaying the data and giving...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.