c# - Empty path name is not legal Error -


i'm trying save 2 images database keep on getting above error, have tried lot cant solve it.

    string filename = "";     string filename2 = "";     private void savereq()     {         try         {             byte[] img = null;             byte[] img2 = null;             filestream fs = new filestream(filename, filemode.open, fileaccess.read);             filestream fs2 = new filestream(filename2, filemode.open, fileaccess.read);              binaryreader br = new binaryreader(fs);             binaryreader br2 = new binaryreader(fs2);             img = br.readbytes((int)fs.length);                img2 = br2.readbytes((int)fs2.length);             sqlconnection cn = new sqlconnection(mysql.con.connectionstring);             string query = "insert build_lic (id,kroky,kroky_3am) values('" + txtid.text + "',@kroky,@kroky_3am)";             cn.open();             mysql.command = new sqlcommand(query, cn);             mysql.command.parameters.add(new sqlparameter("@kroky", img));             mysql.command.parameters.add(new sqlparameter("@kroky_3am", img2));             mysql.command.executenonquery();             cn.close();          }         catch (exception ex)         {             messagebox.show(ex.message);         }     } 

if delete 1 of filestreams(fs,fs2) code work & save image put 1 & want save 2 images u show me how correcting code

make sure filename value has valid file path.

from filestream constructor (string, filemode, fileaccess)

throws argumentexception if path empty string (""), contains white space, or contains 1 or more invalid characters.

you might want have @ file.exists method

determines whether specified file exists.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -