OpenFile() public method

public OpenFile ( ) : Stream
return System.IO.Stream
Beispiel #1
0
        public string _ouvrir(typeFichier tf)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (tf == typeFichier.musique)
            {
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                ofd.Filter = "mp3 files (*.mp3)|*.mp3";
                ofd.FilterIndex = 2;
                ofd.RestoreDirectory = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if (ofd.OpenFile() != null)
                    {
                        try
                        {
                            Lecteur = new Audio(ofd.FileName, false);

                        }
                        catch (Exception esx)
                        {
                            MessageBox.Show("Fichier non reconnu." + esx.HResult);
                            return null;
                        }

                        return ofd.FileName;

                    }
                }
                return null;
            }
            else if (tf == typeFichier.image)
            {
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                ofd.Filter = "JPG (*.jpg)|*.jpg";
                ofd.FilterIndex = 2;
                ofd.RestoreDirectory = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        if (ofd.OpenFile() != null)// On attribue le chemin du fichier à lire au
                        {

                            return ofd.FileName;

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                        return null;
                    }
                }
                return null;

            }
            return null;
        }
 private void menuItemOpen_Click(object sender, System.EventArgs e)
 {
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         if (openFileDialog.FilterIndex == 2)
         {
             Stream stream = openFileDialog.OpenFile();
             byte[] data   = new byte[stream.Length];
             stream.Read(data, 0, data.Length);
             stream.Close();
             string hexStr = Asn1Util.ToHexString(data);
             hexStr           = Asn1Util.FormatString(hexStr, hexLineLen, 2);
             richTextBox.Text = hexStr;
             currentFormat    = DataFormat.HEX;
             SetButtons();
         }
         else
         {
             Stream stream = openFileDialog.OpenFile();
             byte[] data   = new byte[stream.Length];
             stream.Read(data, 0, data.Length);
             stream.Close();
             string dataStr = Asn1Util.BytesToString(data);
             richTextBox.Text = dataStr;
         }
     }
 }
        private void btnSelectSourceSaveFile_onClick(object sender, EventArgs e)
        {
            var fileDialog = new System.Windows.Forms.OpenFileDialog();

            fileDialog.DefaultExt = "bin";
            fileDialog.Filter     = "P4G save file (PC/Vita) (*.bin)|*.bin";

            DialogResult result = fileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string openFileName = fileDialog.FileName;
                try
                {
                    // Output the requested file in richTextBox1.
                    Stream s = fileDialog.OpenFile();
                    s.Close();

                    fileOpened = true;

                    tbxSourceSaveFile.Text = openFileName;
                }
                catch (Exception exp)
                {
                    MessageBox.Show("An error occurred while attempting to load the file. The error is:"
                                    + System.Environment.NewLine + exp.ToString() + System.Environment.NewLine);
                    fileOpened = false;
                }
            }
        }
Beispiel #4
0
        private void SendFile_Click(object sender, RoutedEventArgs e)
        {
            if (CtsIndicator.IsChecked != true || DsrIndicator.IsChecked != true)
            {
                MessageBox.Show("Принимающая сторона не готова к логическому соединению.");
                return;
            }

            fileStream = fileDialog.OpenFile();
            var hash = new SHA512CryptoServiceProvider().ComputeHash(fileStream);

            fileStream.Seek(0, SeekOrigin.Begin);

            var stream = new MemoryStream();
            var writer = new BinaryWriter(stream);

            writer.Write((byte)MessageType.FileName);
            writer.Write(fileDialog.SafeFileName);
            writer.Write(fileStream.Length);
            writer.Write(hash); // 64 bytes for security

            sending = true;
            CloseButton.IsEnabled  = false;
            FileBox.IsEnabled      = false;
            DirectoryBox.IsEnabled = false;
            StatusText.Text        = "Установка логического соединения...";
            Title = "Отправляем " + fileDialog.SafeFileName;
            Physical.SetRts(true);
            SendPacket(stream.ToArray());
        }
Beispiel #5
0
        Stream GetImportFile()
        {
            Stream retVal = null;

            System.Windows.Forms.OpenFileDialog saveFileDlg = new System.Windows.Forms.OpenFileDialog();

            saveFileDlg.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDlg.FilterIndex      = 1;
            saveFileDlg.RestoreDirectory = true;

            if (saveFileDlg.ShowDialog() == DialogResult.OK)
            {
                Stream myStream = null;
                try
                {
                    if ((myStream = saveFileDlg.OpenFile()) != null)
                    {
                        retVal = myStream;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            return(retVal);
        }
Beispiel #6
0
        private void PictureBoxDoubleClick(object sender, EventArgs e)
        {
            int id = GetID(new Point(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y));

            if (id < 0)
            {
                return;
            }

            Bitmap origBitmap = _bitmaps[id];

            System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
            string dimensions = origBitmap.Width + " x " + origBitmap.Height;

            fileDialog.Filter = "Bitmap images (*.bmp)|*.bmp";
            fileDialog.Title  = "Please choose a bitmap file with the following dimensions: " + dimensions;
            DialogResult result = fileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                System.IO.Stream strm = fileDialog.OpenFile();
                Bitmap           b    = new Bitmap(strm);

                if (b.Width != origBitmap.Width || b.Height != origBitmap.Height)
                {
                    string fileDims = b.Width + " x " + b.Height;
                    throw new ArgumentException("Size of loaded image (" + fileDims + ") does not match original (" + dimensions + ")");
                }

                // Modify the block with the new images
                _file.SetBitmap(b, id);
                _pictureBox.Refresh();
                _file.save();
            }
        }
Beispiel #7
0
        public void LoadPhonetic()
        {
            if (this.openPhoneticDialog.ShowDialog(this) == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                // open dictionary file
                FileStream   fs = (FileStream)openPhoneticDialog.OpenFile();
                StreamReader sr = new StreamReader(fs, Encoding.UTF7);

                this.txtPhonetic.Text = "";

                // read line by line
                while (sr.Peek() >= 0)
                {
                    string tempLine = sr.ReadLine().Trim();
                    if (!tempLine.StartsWith("#") &&
                        !tempLine.StartsWith("version") &&
                        !tempLine.StartsWith("followup") &&
                        !tempLine.StartsWith("collapse_result") &&
                        tempLine.Length > 0)
                    {
                        this.txtPhonetic.AppendText(tempLine + "\r\n");
                    }
                }
                // close reader
                sr.Close();
                // close stream
                fs.Close();
            }
            this.Cursor = Cursors.Default;
        }
Beispiel #8
0
 private void loadToolStripMenuItem_Click(object sender, EventArgs e)
 {
     System.Windows.Forms.OpenFileDialog opendialogfile = new System.Windows.Forms.OpenFileDialog();
     opendialogfile.Filter           = "Lua File (*.lua)|*.lua|Text File (*.txt)|*.txt";
     opendialogfile.FilterIndex      = 2;
     opendialogfile.RestoreDirectory = true;
     if (opendialogfile.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     try
     {
         fastColoredTextBox1.Text = "";
         System.IO.Stream stream;
         if ((stream = opendialogfile.OpenFile()) == null)
         {
             return;
         }
         using (stream)
             this.fastColoredTextBox1.Text = System.IO.File.ReadAllText(opendialogfile.FileName);
     }
     catch (Exception)
     {
         int num = (int)MessageBox.Show("An error has occured", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Beispiel #9
0
        private void button_loadscript_Click(object sender, System.EventArgs e)
        {
            //load script
            this.Enabled = false;            //diable the screen

            try
            {
                DialogResult okOrNo;                                             //dialog return value, if it is DialogResult.OK then everything is OK

                openFileDialog1.InitialDirectory = Globals.PATH + "\\Scripts";   //Initial dir, where it begins looking at.
                openFileDialog1.Filter           = "Script Files (*.l2s)|*.l2s"; //this particualr format is for one file type.
                openFileDialog1.FilterIndex      = 1;                            //this means that the first description is the default one.
                openFileDialog1.RestoreDirectory = true;                         //The next dialog box opened will start at the inital dir.
                okOrNo = openFileDialog1.ShowDialog();                           //open the dialog box and save the result.

                if (okOrNo == DialogResult.OK)                                   //if the dialog box works
                {
                    richTextBox_script.Text = "";

                    StreamReader filein = new StreamReader(openFileDialog1.OpenFile()); //create a new streamwritter from the stream it returns
                    ReadScript(filein);                                                 //load everything
                    filein.Close();                                                     //close the file
                }
            }
            catch
            {
                Globals.l2net_home.Add_Error("ERROR WHILE LOADING SCRIPT!" + System.Environment.NewLine + "Is the script running?");
            }

            this.Enabled = true;            //renable everything
        }
Beispiel #10
0
        private void Add_LeftFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog _dialog = new OpenFileDialog();
            Stream _readStream = null;

            if (_dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((_readStream = _dialog.OpenFile()) != null)
                    {
                        using (_readStream)
                        {
                            TextBoxLeft.m_textController.Clear();
                            TextBoxLeft.m_textController.Setup(File.ReadAllText(_dialog.FileName));
                            TextBoxLeft.m_path = _dialog.FileName;
                            lbl_fileLeft.Text = _dialog.FileName.ToString();

                            if (TextBoxRight.m_textController.Lines.Count != 0)
                            {
                                AddHistoryTracking(lbl_fileLeft.Text, lbl_fileRight.Text);
                            }

                            CompareFileAndPresentation();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.MessageBox.Show("THIS NEEDS FIXED", "THIS NEEDS FIXED", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            System.IO.Stream myStream = null;
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\\Downloads";
            openFileDialog.Filter           = "RIS Files (*.ris)|*.ris|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            System.IO.StreamReader reader = new System.IO.StreamReader(myStream);
                            Data = reader.ReadToEnd();
                            // ChemInfo.Reference reference = new ChemInfo.Reference(string.Empty, string.Empty, Data);
                            //textBox1.Text = reference.ToString();
                            label5.Text = string.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
 internal static bool OpenSaveFile(GameBoard board)
 {
     OpenFileDialog d = new OpenFileDialog();
     d.Filter = "Kvj Save File (*.kvj)|*.kvj";
     if (d.ShowDialog(board) != DialogResult.Cancel)
     {
         try
         {
             using (FileStream fs = (System.IO.FileStream)d.OpenFile())
             {
                 byte[] bytes = new byte[fs.Length];
                 fs.Read(bytes, 0, bytes.Length);
                 board.Deserialize(bytes);
             }
             return true;
         }
         catch (Exception)
         {
             return false;
         }
     }
     else
     {
         return false;
     }
 }
Beispiel #13
0
        private void OpenToolStripMenuItemClick(object sender, System.EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
                                     {
                                         InitialDirectory = "C:\\",
                                         Filter = "PNG (*.png*)|*.png|JPEG (*.jpg)|*.jpg",
                                         FilterIndex = 2,
                                         RestoreDirectory = true
                                     };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream imageStream;
                using (imageStream = openFileDialog.OpenFile())
                {
                    this._currentImage = new Bitmap(imageStream);

                    var miniature = new Bitmap(sourcePictureBox.Width, sourcePictureBox.Height);
                    using (var g = Graphics.FromImage(miniature))
                    {
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.DrawImage(this._currentImage, 0, 0, miniature.Width, miniature.Height);
                    }

                    sourcePictureBox.Image = miniature;
                }
            }
        }
        private void btnOpenXml_Click(object sender, EventArgs e)
        {
            LoadXML xml = new LoadXML();
            string pfad = null;
            //Öffnet OpenFileDialog
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            DialogResult result = openFileDialog1.ShowDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (openFileDialog1.OpenFile() != null)
                {
                    //Öffnet Explorer und ermittelt den Eingegebenen Dateipfad
                    string file = openFileDialog1.FileName;
                    try
                    {
                        pfad = openFileDialog1.FileName;
                    }
                    //TODO: Ausnahme hinzufügen
                    catch (IOException)
                    {

                    }
                }
                //Dateipfad wird an die Klasse ladeXML übergeben
                Console.WriteLine(result);
                Console.WriteLine(pfad);
                xml.ladeXML(pfad);

            }
        }
Beispiel #15
0
    public void OpenFileDialog()
    {
        Stream myStream = null;

        ofd.Filter           = fileFilter;
        ofd.FilterIndex      = 2;
        ofd.RestoreDirectory = true;

        if (ofd.ShowDialog() == DialogResult.OK)
        {
            if ((myStream = ofd.OpenFile()) != null)
            {
                using (myStream)
                {
                    // Insert code to read the stream here.
                    selectedAssetPath = ofd.FileName;
                    ChoosedCorrectFile();
                }
                myStream.Dispose();
            }
        }
        else
        {
            FileSelectionNotPerfromed();
        }
    }
Beispiel #16
0
 private void btnImportFile_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog dialog = new OpenFileDialog();
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             using (Stream fs = dialog.OpenFile())
             {
                 if (fs.Length > (long)Int32.MaxValue)
                 {
                     throw new Exception(string.Format("File is large than {0} KB", Math.Round(Int32.MaxValue / 1024.0, 3)));
                 }
                 txtValue.Text = string.Format("The content of file {0}", dialog.FileName);
                 using (BinaryReader reader = new BinaryReader(fs))
                 {
                     mByteData = reader.ReadBytes((int)fs.Length);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #17
0
        private void fileLoad()
        {
            OpenFileDialog open = new OpenFileDialog();
            Stream stre;
            open.DefaultExt = "txt";
            open.Filter = "文字檔(*.txt)|*.txt";
            open.ReadOnlyChecked = true;
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                is_file_path2 = open.FileName;
                stre = open.OpenFile();
                try
                {
                    richTextBox1.LoadFile(stre, RichTextBoxStreamType.PlainText);
                }
                catch (Exception file_exce)
                {
                    MessageBox.Show(file_exce.ToString(), "錯誤訊息");
                }
                finally
                {
                    //關閉stream才算關閉這個檔案,只有對openfiledialog做dispose是沒用的,
                    //還是會出現有人正在使用這個檔案
                    stre.Close();

                    open.Reset();
                    open.Dispose();
                    open = null;
                }
            }
        }
Beispiel #18
0
        private void btnProcurar_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtarquivo.Text = openFileDialog1.FileName;
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {

                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
        private void buttonEscogerImagen_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Image files (*.jpg)|*.jpg|Image files (*.png)|*.png";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string imagen;
                            imagen = openFileDialog1.FileName;
                            pictureBoxImagen.ImageLocation = imagen;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "c:\\";
            ofd.Filter = "txt files (*.txt)|*.txt";
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = ofd.OpenFile()) != null)
                    {
                        StreamReader reader = new StreamReader(myStream);
                        str = reader.ReadToEnd();
                        inputBox1.Text = str;

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message);
                }
            }
        }
Beispiel #21
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                Stream str = null;
                XmlSerializer xs = new XmlSerializer(typeof(Session));

                ofd.Filter = "spread profiles (*.xml)|*.xml";
                ofd.FilterIndex = 1;
                ofd.RestoreDirectory = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    if ((str = ofd.OpenFile()) != null)
                    {
                        using (str)
                            session = (Session)xs.Deserialize(str);

                        pgInstrumentA.SelectedObject = session.instrumentA;
                        pgInstrumentB.SelectedObject = session.instrumentB;
                        pgSpread.SelectedObject = session.spread;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #22
0
        // Open option on File menu
        // Purpose: Opens a file, reads in data to Employee object
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream fileStream = null;
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.InitialDirectory = "C:\\";
            openFile.Filter = "text files (*.txt) | *.txt";

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                if ((fileStream = openFile.OpenFile()) != null)
                {
                    StreamReader data = new StreamReader(fileStream);

                    string name = data.ReadLine();
                    int empNo = int.Parse(data.ReadLine());
                    string address = data.ReadLine();
                    string phone = data.ReadLine();
                    double hours = double.Parse(data.ReadLine());
                    double wage = double.Parse(data.ReadLine());

                    currentEmployee = new Employee(name, empNo, address, phone, wage, hours);

                    txtName.Text = currentEmployee.Name;
                    txtEmployeeNumber.Text = currentEmployee.EmployeeNumber.ToString();
                    txtAddress.Text = currentEmployee.Address;
                    txtPhone.Text = currentEmployee.Phone;
                    txtHours.Text = currentEmployee.Hours.ToString();
                    txtHourlyWage.Text = String.Format("{0:C}",currentEmployee.HourlyRate);
                }
            }
        }
Beispiel #23
0
        private void RestoreAllDataClick(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

            openFileDialog1.InitialDirectory = Path.GetTempPath();
            openFileDialog1.Filter           = "archive files (*.zip)|*.7z|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (ZipArchive archive = new ZipArchive(openFileDialog1.OpenFile()))
                    {
                        // TODO: What does restore mean? Right now, just extracts to temp.
                        // would have to do some somersaults to switch DB and change app context to stored config.
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            entry.ExtractToFile(Path.Combine(Path.GetTempPath(), entry.FullName), true);
                        }
                    }
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("Cannot access zip file.", "ERROR");
                }
            }
        }
Beispiel #24
0
        private void Import_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog ImportFile = new OpenFileDialog();

            ImportFile.Filter = "Wavefront Obj (*.obj)|*.obj|Collada (*.dae)|*.dae|3DS Max (*.3ds)|*.3ds|FBX Datei (*.fbx)|*.fbx";
            ImportFile.FilterIndex = 2;
            ImportFile.RestoreDirectory = true;

            if (ImportFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = ImportFile.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
        private void openFileDialogButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            //openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream myStream = openFileDialog.OpenFile();
                    if (null != myStream)
                    {
                        using (myStream)
                        {
                            // Insert code to read from the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read a file. Original error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void jsonbutton_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "client_secret.json (.json)|*.json|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            var jsonname = openFileDialog1.FileName;
                            dpfad.Text = jsonname;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #27
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            var openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location)
            };

            if (openFileDialog1.ShowDialog() != DialogResult.OK)
                return;
            try
            {
                var document = new XmlDocument();
                document.Load(openFileDialog1.OpenFile());
                UpdateBotAndText(document, openFileDialog1.FileName);
//                xmlEditor1.AllowXmlFormatting = true;
//                xmlEditor1.Text = document.OuterXml;
//                xmlEditor1.ReFormat();


            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Error: Could not read file from disk. Original error: " + ex.Message);
            }
        }
Beispiel #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Multiselect = false,  // 複数選択の可否
                Filter =  // フィルタ
                "Excelファイル|*.xlsx;",
            };

            //ダイアログを表示
            Stream myStream = null;
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                // ダイアログで指定されたファイルを読み込み
                try
                {
                    if ((myStream = dialog.OpenFile()) != null)
                    {
                        // ファイル名を設定
                        textBox1.Text = dialog.FileName;
                        Converter.file_path = dialog.FileName;
                        // 実行ボタンを有効に
                        button2.Enabled = true;
                        myStream.Close();
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.Message + "\n\n指定したファイルを Excel などで開いている場合は、いったん閉じてください。", "ファイル読み込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #29
0
 public static void showDialog()
 {
     var d = new OpenFileDialog();
     if(d.ShowDialog() == DialogResult.OK){
         Console.WriteLine(d.OpenFile().ToString());
     }
 }
Beispiel #30
0
        // Открытие файла
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";//выбор элементов любых типов
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            // Если выбран файл
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {// Пишем имя файла в первое окошко
                            textBox1.Text = openFileDialog1.FileName;
                            textBox2.Text = String.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка: прочитать файл не получилось: " + ex.Message);
                }
            }
        }
 internal bool SelectFileToAdjuct(WfAdjunct adjunct)
 {
     if (adjunct == null)
     {
         throw new NullReferenceException("WfAdjunct cannot be null");
     }
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.Title = "请选择附件";
     dialog.Filter = "Word 文件 (*.doc)|*.txt|All files (*.*)|*.*";
     dialog.FilterIndex = 2;
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         Stream stream = dialog.OpenFile();
         if (stream != null)
         {
             if (adjunct.File == null)
             {
                 adjunct.File = new WfAdjunctFile(adjunct);
             }
             adjunct.File.Data = Read2Buffer(stream, -1);
             stream.Close();
             adjunct.Type = Path.GetExtension(dialog.FileName);
             if (StringHelper.IsNull(adjunct.Name))
             {
                 adjunct.Name = Path.GetFileNameWithoutExtension(dialog.FileName);
             }
             return true;
         }
     }
     return false;
 }
Beispiel #32
0
 private void pbImage_DoubleClick(object sender, System.EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     Stream stream = null;
     ofd.Filter = "Image Files(*.bmp;*.jpg;*.png;*.jpeg)|*.bmp;*.jpg;*.png;*.jpeg|All files (*.*)|*.*";
     ofd.AutoUpgradeEnabled = true;
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if((stream = ofd.OpenFile()) != null)
             {
                 using (stream)
                 {
     #if DEBUG
                     MessageBox.Show("Not implement yet.");
     #endif
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error: Could not read file. Original error: " + ex.Message);
         }
     }
 }
Beispiel #33
0
        private void button2_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            //openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "jpg files (*.jpg)|*.jpg|png files (*.png)|*.png|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            Image theImage = Image.FromStream(myStream);
                            OpenObject objForm = new OpenObject(this);
                            objForm.setImage(theImage);
                            objForm.ShowDialog();
                            //this.pictureBox2.Image = Image.FromStream(myStream);
                            myStream.Close();

                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #34
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // Open file
     Stream myStream = null;
     OpenFileDialog openFileDialog1 = new OpenFileDialog();
     openFileDialog1.InitialDirectory = @"D:\";
     openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*) |*.*";
     openFileDialog1.FilterIndex = 2;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if ((myStream = openFileDialog1.OpenFile()) != null)
             {
                 using (myStream)
                 {
                     richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error : Could not read file from disk:	" + ex.Message);
         }
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = this.appPath_;
            openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx|Excel files 2003~2007 (*.xls)|*.xls|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                            FileStream fs = myStream as FileStream;
                            if (fs != null)
                            {
                                textBox1.Text = fs.Name.ToString();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #36
0
 private void myComputerToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     Stream myStream = null;
     OpenFileDialog theDialog = new OpenFileDialog();
     theDialog.Title = "Open Text File";
     theDialog.Filter = "text files|*.txt";
     theDialog.InitialDirectory = @"C:\";
     if (theDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if ((myStream = theDialog.OpenFile()) != null)
             {
                 using (myStream)
                 {
                     // Insert code to read the stream here.
                     richTextBox1.LoadFile(myStream, RichTextBoxStreamType.PlainText);
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
         }
     }
 }
Beispiel #37
0
        public void OpenFileDialog()
        {
            Stream myStream = null;

            ofd.InitialDirectory = "c:\\";
            ofd.Filter           = "ead files (*.ead) | *.ead |eap files (*.eap) | *.eap | All files(*.*) | *.* ";
            ofd.FilterIndex      = 2;
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = ofd.OpenFile()) != null)
                {
                    using (myStream)
                    {
                        // Insert code to read the stream here.
                        selectedGameProjectPath = ofd.FileName;
                        GameRources.LoadGameProject(selectedGameProjectPath);
                        EditorWindowBase.Init();
                        EditorWindowBase window = (EditorWindowBase)EditorWindow.GetWindow(typeof(EditorWindowBase));
                        window.Show();
                    }
                    myStream.Dispose();
                }
            }
        }
Beispiel #38
0
 private void bBrowse_Click(object sender, EventArgs e)
 {
     string[] fsResult;
     Stream musicListStream = null;
     OpenFileDialog fileDialog = new OpenFileDialog();
     fileDialog.InitialDirectory = "C:\\";
     fileDialog.Filter = "txt file(*.txt)|*.txt";
     fileDialog.FilterIndex = 2;
     fileDialog.RestoreDirectory = true;
     if (fileDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if ((musicListStream = fileDialog.OpenFile()) != null)
             {
                 using (musicListStream)
                 {
                     FileStream mfs = (FileStream)musicListStream;
                     StreamReader sr = new StreamReader(mfs);
                     string _tfsResult = sr.ReadToEnd();
                     byte[] str = Encoding.Default.GetBytes(_tfsResult);
                     fsResult = Encoding.ASCII.GetString(str).Split(new char[] { '\n' });
                     mList.Items.AddRange(fsResult);
                     mfs.Close();
                     sr.Close();
                 }
                
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("File cannot be read", ex.Message);
         }
     }
 }
Beispiel #39
0
        private async void ButtonOpenSnapshot_OnClick(object sender, RoutedEventArgs e)
        {
            var fileDialog = new OpenFileDialog {
                Filter = @"JSON files (*.json)|*.json"
            };

            if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (var reader = new StreamReader(fileDialog.OpenFile(), Encoding.UTF8))
                    {
                        var snapshot = JsonConvert.DeserializeObject <Snapshot>(reader.ReadToEnd());

                        if (snapshot != null)
                        {
                            ((SnapshotsViewModel)DataContext).Snapshots.Add(snapshot);
                        }
                    }
                }
                catch (Exception exception)
                {
                    await this.ShowMessageAsync("Error", exception.Message);
                }
            }
        }
Beispiel #40
0
        private void btnLoadCsvToPool_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "CSV files (*.csv)|*.csv";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (StreamReader sr = new StreamReader(ofd.OpenFile()))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (IsFormClosing)
                            break;

                        string[] csvTokens = line.Split(',');
                        //if (Convert.ToInt32(csvTokens[0]) > 30000)
                        //{
                            CM.AddUrl("http://" + csvTokens[1]);
                            Application.DoEvents();
                            toolStripStatusLabel2.Text =
                                string.Format("Loading alexa url: {0}", csvTokens[0]);
                        //}
                    }

                    toolStripStatusLabel2.Text = string.Empty;
                    sr.Close();
                }
            }
        }
Beispiel #41
0
        private void btnSendImage_Click(object sender, System.EventArgs e)
        {
            Stream imageStream;

            System.Messaging.Message mImage = new System.Messaging.Message();

            openFileDialog1.Filter      = "image files (.bmp,.jpg,.gif)|*.bmp;*.jpg;*.gif;*.exe";
            openFileDialog1.FilterIndex = 1;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((imageStream = openFileDialog1.OpenFile()) != null)
                {
                    mImage.BodyStream = imageStream;

                    try
                    {
                        MyMQ.Send(mImage);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + " " + ex.InnerException.Message);
                    }
                    finally
                    {
                        imageStream.Close();
                    }
                }
            }
        }
Beispiel #42
0
        private void btnOpenTextFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openTextDialog = new OpenFileDialog();
            laadTextDialog(openTextDialog);

            string ext, file, path, content;

            if (openTextDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((stream = openTextDialog.OpenFile()) != null)
                    {
                        using (stream)
                        {
                            var streamReader = new StreamReader(stream);
                            content = streamReader.ReadToEnd();

                            richTextBox1.Text = content;

                            ext = Path.GetExtension(openTextDialog.FileName);
                            file = Path.GetFileName(openTextDialog.FileName);
                            path = Path.GetDirectoryName(openTextDialog.FileName);
                            label1.Text = path + "\\" + file;

                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #43
0
        public static bool GetFilePath(out String path)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            path = null;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        path = openFileDialog1.FileName;
                        myStream.Dispose();
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);

                }
            }
            return false;
        }
Beispiel #44
0
        private void openfileClicked(object sender, EventArgs e)
        {
           
            OpenFileDialog openFildialog1 = new OpenFileDialog();
            // Set filter option and file index
            openFildialog1.Filter = "Text files(.txt)|*.txt|All Files(*.*)|*.*";
            openFildialog1.FilterIndex = 1;
            openFildialog1.Multiselect = true;

            Stream myStream;
           
            if (openFildialog1.ShowDialog() == DialogResult.OK)
            {
                //open the selected file to read.
                myStream = openFildialog1.OpenFile();

                using (StreamReader reader = new StreamReader(myStream))
                {
                    //Read the first line for the file and write it in the textbox
                    Contentbox.Text = reader.ReadToEnd();
                }
                myStream.Close();
                /* This is second method, I'd like to compare which method is better
                if ((myStream = openFildialog1.OpenFile()) != null)
                {
                    string strfileName = openFildialog1.FileName;
                    string filetext = File.ReadAllText(strfileName);
                    Contentbox.Text = filetext;
                }*/
            }
            
        }
        private void OpenBinaryFile()
        {
            Stream stream = openFileDialog.OpenFile();

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, data.Length);
            currentFileName = openFileDialog.FileName;
            currentFileSize = stream.Length;
            stream.Close();
            string hexStr = Asn1Util.ToHexString(data);

            hexStr           = Asn1Util.FormatString(hexStr, hexLineLen, 2);
            richTextBox.Text = hexStr;
            currentFormat    = DataFormat.HEX;
            SetButtons();
            ShowFileName();
        }
Beispiel #46
0
 private void onLoad(object sender, System.EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         StreamReader r = new StreamReader(openFileDialog1.OpenFile());
         textBox1.Text = r.ReadToEnd();
         r.Close();
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("THIS NEEDS FIXED", "THIS NEEDS FIXED", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            System.IO.Stream myStream = null;
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "\\Downloads";
            openFileDialog.Filter           = "RIS Files (*.ris)|*.ris|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 1;
            openFileDialog.RestoreDirectory = true;
            var fGroup = from myRow in this.m_fGroups.AsEnumerable()
                         where myRow.Field <string>("Name") == this.functionalGroupComboBox.SelectedItem.ToString()
                         select myRow;
            List <Int64> groups = new List <Int64>();

            foreach (DataRow dr in fGroup)
            {
                groups.Add(Convert.ToInt64(dr["id"]));
            }
            var results = from myRow in this.m_fGroups.AsEnumerable()
                          where myRow.Field <string>("Name") == this.namedReactionComboBox.SelectedItem.ToString() &&
                          myRow.Field <Int64>("Functional_Group_id") == groups[0]
                          select myRow;
            List <Int64> rxn = new List <Int64>();

            foreach (DataRow dr in results)
            {
                rxn.Add(Convert.ToInt64(dr["id"]));
            }
            FunctionalGroupId = groups[0];
            ReactionNameId    = rxn[0];
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            System.IO.StreamReader reader = new System.IO.StreamReader(myStream);
                            Data          = reader.ReadToEnd();
                            Reference     = new Reference(groups[0], rxn[0], Data);
                            textBox1.Text = Reference.ToString();
                            label5.Text   = string.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #48
0
 private void _fileMenuOpen_Click(object sender, System.EventArgs e)
 {
     if (_openFileDialog.ShowDialog() == DialogResult.OK)
     {
         Stream stream = _openFileDialog.OpenFile();
         if (stream != null)
         {
             _screenControl.Screen.Load(stream);
             _screenControl.Invalidate();
             stream.Close();
         }
     }
 }
Beispiel #49
0
        public void LoadAffix()
        {
            if (this.openAffixDialog.ShowDialog(this) == DialogResult.OK)
            {
                this.Cursor          = Cursors.WaitCursor;
                this.txtTry.Text     = "";
                this.txtReplace.Text = "";
                this.txtPrefix.Text  = "";
                this.txtSuffix.Text  = "";

                // open dictionary file
                FileStream   fs = (FileStream)openAffixDialog.OpenFile();
                StreamReader sr = new StreamReader(fs, Encoding.UTF7);

                // read line by line
                while (sr.Peek() >= 0)
                {
                    string tempLine = sr.ReadLine().Trim();
                    if (tempLine.Length > 3)
                    {
                        switch (tempLine.Substring(0, 3))
                        {
                        case "TRY":
                            this.txtTry.Text = tempLine.Substring(4);
                            break;

                        case "PFX":
                            this.txtPrefix.AppendText(tempLine.Substring(4) + "\r\n");
                            break;

                        case "SFX":
                            this.txtSuffix.AppendText(tempLine.Substring(4) + "\r\n");
                            break;

                        case "REP":
                            if (!char.IsNumber(tempLine.Substring(4)[0]))
                            {
                                this.txtReplace.AppendText(tempLine.Substring(4) + "\r\n");
                            }
                            break;
                        }
                    }
                }
                // close reader
                sr.Close();
                // close stream
                fs.Close();
            }
            this.Cursor = Cursors.Default;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Stream myStream;

            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    string strfilename = openFileDialog1.FileName;
                    richTextBox1.Text = strfilename;
                }
            }
        }
Beispiel #51
0
 private void openFileDialog(object sender, System.EventArgs e)
 {
     if (of_Browse.ShowDialog() == DialogResult.OK)
     {
         try {
             if ((of_Browse.OpenFile()) != null)
             {
                 tb_InputPath.Text = of_Browse.FileName;
             }
         }
         catch (Exception ex) {
             MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
         }
     }
 }
Beispiel #52
0
        private void bLoad_Click(object sender, System.EventArgs e)
        {
            DialogResult r = ofdSource.ShowDialog(this);

            if (r == DialogResult.OK)
            {
                Stream     s       = ofdSource.OpenFile();
                TextReader rd      = new StreamReader(s);
                string     content = rd.ReadToEnd();
                rd.Close();
                s.Close();
                Regex regex = new Regex("([^\r])(\n+)");
                tbSource.Text = regex.Replace(content, new MatchEvaluator(changeUnixLineEndings));
            }
        }
Beispiel #53
0
 private void browseHandler(TextBox textbox)
 {
     if (of_Browse.ShowDialog() == DialogResult.OK)
     {
         try {
             if ((of_Browse.OpenFile()) != null)
             {
                 textbox.Text = of_Browse.FileName;
             }
         }
         catch (Exception ex) {
             MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
         }
     }
 }
Beispiel #54
0
        /// <summary>
        /// //Get MNIST Image file'header
        /// </summary>
        protected bool MnistImageFileHeader()
        {
            if (_bImageFileOpen == false)
            {
                byte[] m_byte          = new byte[4];
                var    openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
                openFileDialog1.Filter = "Mnist Image file (*.idx3-ubyte)|*.idx3-ubyte";
                openFileDialog1.Title  = "Open Minist Image File";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    _MnistImageFileName = openFileDialog1.FileName;

                    try
                    {
                        load_ImageFile_stream = new System.IO.BinaryReader(openFileDialog1.OpenFile());
                        //Magic number
                        load_ImageFile_stream.Read(m_byte, 0, 4);
                        Array.Reverse(m_byte, 0, 4);
                        _ImageFileBegin.nMagic = BitConverter.ToInt32(m_byte, 0);
                        //number of images
                        load_ImageFile_stream.Read(m_byte, 0, 4);
                        //High-Endian format to Low-Endian format
                        Array.Reverse(m_byte, 0, 4);
                        _ImageFileBegin.nItems = BitConverter.ToInt32(m_byte, 0);
                        _nItems = (uint)_ImageFileBegin.nItems;
                        //number of rows
                        load_ImageFile_stream.Read(m_byte, 0, 4);
                        Array.Reverse(m_byte, 0, 4);
                        _ImageFileBegin.nRows = BitConverter.ToInt32(m_byte, 0);
                        //number of columns
                        load_ImageFile_stream.Read(m_byte, 0, 4);
                        Array.Reverse(m_byte, 0, 4);
                        _ImageFileBegin.nCols = BitConverter.ToInt32(m_byte, 0);
                        _bImageFileOpen       = true;
                        return(true);
                    }
                    catch
                    {
                        _bImageFileOpen = false;
                        return(false);
                    }
                }
                return(false);
            }
            return(true);
        }
Beispiel #55
0
 private void selectButton_Click(object sender, EventArgs e)
 {
     if (loadProject1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             var filePath = loadProject1.FileName;
             using (Stream str = loadProject1.OpenFile())
             {
                 Process.Start("notepad.exe", filePath);
             }
         }
         catch (SecurityException ex)
         {
             MessageBox.Show($"Security error. message: {ex.Message}" + $"Details: {ex.StackTrace}");
         }
     }
 }
Beispiel #56
0
 private void networkParametersToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var openFileDialog1 = new System.Windows.Forms.OpenFileDialog {
         Filter = "Mnist Neural network file (*.nnt)|*.nnt", Title = "Open Neural network File"
     })
     {
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             _MainMutex.WaitOne();
             _mnistWeightsFile = openFileDialog1.FileName;
             var fsIn = openFileDialog1.OpenFile();
             var arIn = new Archive(fsIn, ArchiveOp.load);
             _NN.Serialize(arIn);
             fsIn.Close();
             _MainMutex.ReleaseMutex();
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (o != null)
        {
            if (o.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (o.OpenFile() != null)
                {
                    string fileName = o.FileName;
                    if (loadType == "graphData")
                    {
                        graph_dataset  = File.ReadAllText(fileName);
                        file_name.text = fileName;
                    }
                    if (loadType == "attributeData")
                    {
                        attribute_dataset   = File.ReadAllText(fileName);
                        attribute_text.text = fileName;
                    }
                }

                o        = null;
                loadType = "";
                print("close dialog");
            }
        }
        if (is_quadrant != null)
        {
            quadrant_layout_on = is_quadrant.isOn;
        }
        if (k_cluster_label != null)
        {
            int output;
            if (Int32.TryParse(k_cluster_label.text, out output))
            {
                k_clusters = output;
            }
            else
            {
                k_cluster_label.text = "";
            }
        }
    }
Beispiel #58
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            Stream myStream = null;

            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

            //openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Image Files (*.png)|*.png";
            //openFileDialog1.FilterIndex = 2;
            //openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            MemoryStream ms = new MemoryStream();
                            myStream.CopyTo(ms);
                            ImageData = ms.ToArray();

                            BitmapImage  biImg = new BitmapImage();
                            MemoryStream ms2   = new MemoryStream(ImageData);
                            biImg.BeginInit();
                            biImg.StreamSource = ms2;
                            biImg.EndInit();

                            Image.Fill = new ImageBrush
                            {
                                ImageSource = biImg
                            };
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Beispiel #59
0
 private void menu_load_Click(object sender, System.EventArgs e)
 {
     System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
     ofd.Title  = "Load Adventure";
     ofd.Filter = "Adventure Builder Files (*.adv)|*.adv";
     ofd.ShowDialog(this);
     try{
         Stream strm = ofd.OpenFile();
         AdventurePersistance pers = new AdventurePersistance(strm);
         m_graph          = (RoomGraph)pers.load();
         m_settings       = (Settings)pers.load();
         m_settings.Graph = (RoomGraph)m_graph;
         strm.Close();
         Invalidate();
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
        private async void menuClick_ImportFrom_deCODEmeAsync(object sender, RoutedEventArgs args)
        {
            var dialog = new WinForms.OpenFileDialog();

            dialog.Filter = deCODEmeReader.fileFilterString;
            if (dialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                // Open the chosen file.
                using (var fileStream = dialog.OpenFile())
                {
                    var streamReader = new StreamReader(fileStream);
                    var database     = await Task.Run(() => (new deCODEmeReader(streamReader)).Read());

                    App.document           = database;
                    App.documentSaveStream = null;

                    // Reanalyze after loading the data.
                    InitAnalysis();
                }
            }
        }