예제 #1
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog diagFile = new OpenFileDialog();

            if (diagFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = diagFile.FileName;
                CookBookEntities context = new CookBookEntities();
                try
                {
                    if (context.Connection.State != ConnectionState.Open)
                    {
                        context.Connection.Open();
                    }
                    context.SaveFile(Path.GetFileNameWithoutExtension(txtPath.Text), GetBytesFromFile(txtPath.Text));
                    MessageBox.Show("Upload Successful");
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    context.Dispose();
                }
            }
        }
예제 #2
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog diagFile = new OpenFileDialog();

            if (diagFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = diagFile.FileName;
                using (CookBookEntities context = new CookBookEntities())
                {
                    try
                    {
                        context.SaveFile(Path.GetFileNameWithoutExtension(txtPath.Text), GetBytesFromFile(txtPath.Text));
                        MessageBox.Show("Upload Successful");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }