Le bout de code suivant m'affiche un message erreur que je ne comprends pas
le message est "value cannot be null parameter name : bytes"
veuillez m'aider
private
void button2_Click( object sender, EventArgs e){
string fichARestaurer = "" ; Byte [] maVarBinaire; // demande de confirmation
DialogResult réponse = MessageBox .Show( "Voulez-vous vraiment" + "restaurer le fichier \n " +listView1.SelectedItems[0].Text,
"Restauration de fichier" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question); if (réponse == DialogResult .OK){
//appel de la méthode restauration
// choix de l'emplacement
DialogResult réponse2 = MessageBox .Show( "Voulez-vous" + "restaurer le fichier \n " +listView1.SelectedItems[0].Text +
"A l'emplacement d'origine?" , "Restauration de fichier" , MessageBoxButtons .OKCancel, MessageBoxIcon .Question);
if (réponse2 == DialogResult .OK){
fichARestaurer = listView1.SelectedItems[0].SubItems[1].Text;
}
else {
if (folderBrowserDialog1.ShowDialog() == DialogResult .OK){
fichARestaurer = folderBrowserDialog1.SelectedPath.ToString() +
"\\" + listView1.SelectedItems[0].Text; MessageBox .Show( "fichier a restaurer " + fichARestaurer);}
}
maVarBinaire =
Restauration .RenvoyerCeFichier(fichARestaurer);
try {
File .WriteAllBytes(fichARestaurer, maVarBinaire);}
catch ( ArgumentNullException exception){
MessageBox .Show(exception.Message);}
catch ( FileNotFoundException exception){
MessageBox .Show(exception.Message);}
catch (System.Security. SecurityException exception){
MessageBox .Show(exception.Message);}
catch ( NotSupportedException exception){
MessageBox .Show(exception.Message);}
catch (System.IO. PathTooLongException exception){
MessageBox .Show(exception.Message);}
catch (System.IO. IOException exception){
MessageBox .Show(exception.Message);}
catch ( UnauthorizedAccessException exception){
MessageBox .Show(exception.Message);}
}
}
Voici le code de la classe Restauration
---------------------------------------
publicclassRestauration{
publicstaticByte[] RenvoyerCeFichier( string nomCompletFichier){
Byte[] fichier = newByte[100]; using (SqlConnection maConnexion = newSqlConnection(BDDetailEvenement.RenvoieConnectionString())){
SqlCommand maCommand = newSqlCommand();try{
maConnexion.Open();
maCommand.CommandTimeout = 0;
//configuration commandemaCommand.Connection = maConnexion;
maCommand.CommandType =
CommandType.StoredProcedure;maCommand.CommandText =
"[dbo].[RestaurerLeFichier]";maCommand.Parameters.Add(
"@NomduFichier", SqlDbType.NVarChar);maCommand.Prepare();
//initialisation des paramètresmaCommand.Parameters[
"@NomduFichier"].Value = nomCompletFichier;//exécution ou appel de la procédure paramétrée contenant des requêtes SQL //maCommand.ExecuteNonQuery();object tempObject = maCommand.ExecuteScalar();if (tempObject != null){
fichier = (
Byte[])tempObject; }
elsefichier =
null; }
catch (InvalidOperationException exception){
MessageBox.Show(exception.Message);}
catch (SqlException exception){
MessageBox.Show(exception.Message);}
catch (Exception exception){
MessageBox.Show(exception.Message);}
return fichier;}
}
}
verbeyst