Ejemplo n.º 1
0
        private void dgvStudentIDDocuments_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            switch (e.ColumnIndex)
            {
            case 0:


                var FileObj        = fileStudentIDDocumentBindingSource.Current;
                Data.Models.File x = new Data.Models.File();
                //loop through the properties of the object you want to covert:
                foreach (PropertyInfo pi in FileObj.GetType().GetProperties())
                {
                    try
                    {
                        //get the value of property and try
                        //to assign it to the property of T type object:
                        x.GetType().GetProperty(pi.Name).SetValue(x, pi.GetValue(FileObj, null), null);
                    }
                    catch { }
                }

                folderBrowserDialogForDownloading.ShowDialog();

                if (folderBrowserDialogForDownloading.SelectedPath.Length > 0)
                {
                    try
                    {
                        Data.Models.File CurrentFile = FileHandeling.GetFile(x.FileID);
                        string           path        = folderBrowserDialogForDownloading.SelectedPath + "\\" + x.FileName;
                        System.IO.File.WriteAllBytes(path, CurrentFile.FileImage);
                        MessageBox.Show(x.FileName + ", Successfully Saved to: " + path, "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                break;
            }
        }