private void btnImportImage_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { using (RasterCodecs codecs = new RasterCodecs()) { string outfile = Path.GetFileNameWithoutExtension(dlg.FileName); outfile += ".jp2"; outfile = Path.Combine(_server.Configuration.ImagesFolder, outfile); if (File.Exists(outfile)) { MessageBox.Show("Target file already exists.", "Cannot import", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.Cursor = Cursors.WaitCursor; codecs.Convert(dlg.FileName, outfile, Leadtools.RasterImageFormat.Jp2, 0, 0, 0, null); this.Cursor = Cursors.Default; MessageBox.Show(String.Format("{0} has been imported to {1}.", dlg.FileName, outfile), "Imported", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }