OpenFileDialog openFileDialog1 = new OpenFileDialog();
private void SelectFileultraButton_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "All Files (*.*)|*.*";
openFileDialog1.Title = "Select File";
if (DialogResult.Cancel == openFileDialog1.ShowDialog())
{
return;
}
fileNameUltraTextEditor.Text = openFileDialog1.FileName;
string fileName = Path.GetFileName(fileNameUltraTextEditor.Text.ToString());
byte[] content = ReadFileToByteArray(fileName);
ImageUpload CurrentFile = bsFile.Current as ImageUpload;
CurrentFile.File= content;
CurrentFile.FileName = fileName;
}
protected static byte[] ReadFileToByteArray(string fileName)
{
FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
long len;
len = fileStream.Length;
Byte[] fileAsByte = new Byte[len];
fileStream.Read(fileAsByte, 0, fileAsByte.Length);
MemoryStream memoryStream = new MemoryStream(fileAsByte);
return memoryStream.ToArray();
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
if (PM.HasChanges())
{
try
{
PM.SaveChanges();
MessageBox.Show("Sucessfully saved");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
else
{
MessageBox.Show("Nothing to save");
}
}