Example #1
2
 protected void Open_Click(Object sender, EventArgs e)
 {
     OpenFileDialog o = new OpenFileDialog();
     if(o.ShowDialog() == DialogResult.OK) {
       Stream file = o.OpenFile();
       StreamReader reader = new StreamReader(file);
       char[] data = new char[file.Length];
       reader.ReadBlock(data,0,(int)file.Length);
       text.Text = new String(data);
       reader.Close();
     }
 }
 private void InitializeStreamBitmap()
 {
     try
     {
         OpenFileDialog openFileDialog1 = new OpenFileDialog();
         if (openFileDialog1.ShowDialog() == DialogResult.OK)
         {
             Stream myStream = null;
             if ((myStream = openFileDialog1.OpenFile()) != null)
             {
                 bitmap1 = new Bitmap(myStream);
                 str = openFileDialog1.FileName;
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("There was an error opening the image file.");
     }
 }
Example #3
0
    //konstruktor wczytujący kalendarz z pliku
    public Aplikacja()
    {
        kalendarz = new Kalendarz();
        data = new Data_dzien();
        while (data.DzienTygodnia() != DniTygodnia.poniedziałek) { data--; }

        //inicjalizacja OpenFileDialog
        otwórz_plik = new OpenFileDialog();
        otwórz_plik.InitialDirectory = "c:\\";
        otwórz_plik.FileName = "";
        otwórz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
        otwórz_plik.FilterIndex = 2;
        otwórz_plik.RestoreDirectory = true;
        //**************KONIEC INICJALIZACJI OpenFileDialog**************

        //inicjalizacja SaveFileDialog
        zapisz_plik = new SaveFileDialog();
        zapisz_plik.AddExtension = true;
        zapisz_plik.FileName = "";
        zapisz_plik.InitialDirectory = "c:\\";
        zapisz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
        zapisz_plik.FilterIndex = 1;
        zapisz_plik.RestoreDirectory = true;
        //**************KONIEC INICJALIZACJI SaveFileDialog**************

        if (otwórz_plik.ShowDialog() == DialogResult.OK)
        {
            Stream plik = otwórz_plik.OpenFile();
            kalendarz.Wczytaj(plik);
            plik.Flush();
            plik.Close();
        }
    }
Example #4
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            // locals
            Stream myStream = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();
            string lastDirectory = GetRegKey("lastDirectory");
            //set up file dialog
            openFileDialog.Filter = "SQL Files (*.sql)|*.sql|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.InitialDirectory = (lastDirectory == "") ? "c:\\" : lastDirectory;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        //show file in ui
                        txtFileName.Text = openFileDialog.FileName;
                        //save dir to reg

                        this.SetRegKey("lastDirectory", Path.GetDirectoryName(openFileDialog.FileName));
                        LoadChangeList(openFileDialog.FileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Problem processing input file.\r\nOriginal error: " + ex.Message);
                }
            }
        }
Example #5
0
        private ImageSource LoadImage()
        {
            var dialog = new OpenFileDialog
            {
                Filter = EditorLocalizer.GetString(EditorStringId.ImageEdit_OpenFileFilter)
            };

            if (dialog.ShowDialog() == true)
            {
                var e = new ImageLoadingEventArgs(dialog.FileName);
                OnImageLoading(e);
                if (e.IsCanceled)
                {
                    return(null);
                }

                using (var stream = dialog.OpenFile())
                {
                    var data = new MemoryStream(stream.GetDataFromStream());
                    return(ImageHelper.CreateImageFromStream(data));
                }
            }
            return(null);
        }
Example #6
0
 private async void OpenOwnEndpoint_OnClick(object sender, RoutedEventArgs e)
 {
     this.OpenOwnEndpoint.IsEnabled = false;
     this.OpenOwnEndpoint.Cursor    = Cursors.AppStarting;
     try
     {
         var  dialog = new OpenFileDialog();
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             using (var fileStream = dialog.OpenFile())
             {
                 var reader           = new BinaryReader(fileStream, Encoding.UTF8);
                 var addressBookEntry = reader.DeserializeDataContract <Uri>();
                 await this.SetEndpointAsync(await OwnEndpoint.OpenAsync(fileStream), addressBookEntry);
             }
         }
     }
     finally
     {
         this.OpenOwnEndpoint.Cursor    = Cursors.Arrow;
         this.OpenOwnEndpoint.IsEnabled = true;
     }
 }
Example #7
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create Stream
            Stream myStream = null;

            //Initialize OpenFileDialog object
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = "c:\\",
                Filter           = "text files (*.txt)|*txt"
            };

            //Confirm dialog created successfully
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //If file was selected
                if ((myStream = openFileDialog.OpenFile()) != null)
                {
                    //Create StreamReader and read in the selected file
                    StreamReader data = new StreamReader(myStream);
                    textBox.Text = data.ReadLine( );
                }
            } // end if
        }     // end method OpenToolStripMenuItem_Click()
Example #8
0
        /// <summary>
        /// Si appui sur le nouton de'ouverture d'un mapping
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Open_button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Nullable <bool> result = opendial.ShowDialog();

                if (result == true)
                {
                    BinaryFormatter format = new BinaryFormatter();
                    Stream          STRE   = opendial.OpenFile();

                    _APC40Map = (APC40Mapping)format.Deserialize(STRE);

                    _APC40.LinkMapping(_APC40Map);
                    MapName_TextBox.Text = _APC40Map.name;

                    STRE.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur pendant l'ouverture d'un nouveau mapping :\n" + ex.Message + "\nveuillez réesayer");
            }
        }
        private void button6_Click(object sender, EventArgs e)  // deserializuj
        {
            Stream         str = null;
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = @"./";
            ofd.Title            = "Wybierz plik tekstowy, z którego chcesz wczytać dane";
            ofd.Filter           = "Pliki xml (*.xml)|*.xml|Wszystkie pliki (*.*)|*.*";
            ofd.FilterIndex      = 1;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((str = ofd.OpenFile()) != null)
                    {
                        using (str)
                        {
                            XmlSerializer serializer = new XmlSerializer(typeof(List <Samochod>));
                            samochody = (List <Samochod>)serializer.Deserialize(str);
                            dataGridView1.Rows.Clear();

                            for (int i = 0; i < samochody.Count(); i++)
                            {
                                dataGridView1.Rows.Add(samochody[i].nrRejestracyjny, samochody[i].marka, samochody[i].rokProdukcji, samochody[i].kolor, samochody[i].iloscPasazerow);
                            }
                        }
                    }
                    MessageBox.Show("Deserializacja się powiodła.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #10
0
        private async void menuObjectFromSerializedStream_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "All Files (*.*)|*.*";

                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        using (Stream stm = dlg.OpenFile())
                        {
                            Guid   clsid;
                            object obj = COMUtilities.OleLoadFromStream(stm, out clsid);
                            await HostObject(m_registry.MapClsidToEntry(clsid), obj, obj is IClassFactory);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void TextFile_Click(object sender, EventArgs e)
        {
            string text = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();

                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        text = reader.ReadToEnd();
                    }
                }
            }

            MainInput.Text = text;
        }
Example #12
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter      = "Файлы xml|*.xml";
            ofd.Multiselect = false;


            var dialogResult = ofd.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                using (var stream = ofd.OpenFile())
                {
                    var result = ProblemConditionsHelper.ReadConditionsFromXmlStream(stream);

                    if (!result.Success)
                    {
                        MessageBox.Show("Во время загрузки задачи возникли непредвиденные ошибки", "Ошибка",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    _variables.Clear();
                    _variables.AddRange(result.Data.Variables);

                    _rules.Clear();
                    _rules.AddRange(result.Data.Rules);

                    inputDataTextBox.Text = "";

                    RefreshVariablesListView();
                    RefreshRulesListView();
                }
            }
        }
        private void radButton3_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            int            row = 0, col = 0;

            if (fd.ShowDialog() == DialogResult.OK)
            {
                StreamReader reader = new StreamReader(fd.OpenFile());

                List <List <int> > list = new List <List <int> >();
                int i = 0, j = 0, l = 0;
                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(',');
                    if (l == 0)
                    {
                        row    = int.Parse(values[0].ToString());
                        col    = int.Parse(values[1].ToString());
                        input0 = Matrix.Create(row, col, 0d);
                    }
                    else
                    {
                        j = 0;
                        foreach (string s in values)
                        {
                            input0[i, j++] = double.Parse(s);
                        }

                        i++;
                    }
                    l++;
                }
                input = input0.Transpose();
            }
        }
        private void EnInputFileButton_Click(object sender, EventArgs e)
        {
            fList.Clear();

            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "All files (*.*)|*.*";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Multiselect      = true;
            openFileDialog1.Title            = "Select File(s)";

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (String file in openFileDialog1.FileNames)
                {
                    try
                    {
                        if ((myStream = openFileDialog1.OpenFile()) != null)
                        {
                            using (myStream)
                            {
                                fList.Add(new FileInfo(file));
                                //MessageBox.Show("File(s) found: " + file.ToString(), "SOURCE FILE(S)");
                            }
                        }
                        EnURLlabel1.Visible = true;
                        EnURLlabel1.Text    = file.ToString();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    }
                }
            }
        }
Example #15
0
        private void btnpath_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

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

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            txtputanja.Text    = openFileDialog1.FileName;
                            pblogo.Image       = new Bitmap(openFileDialog1.FileName);
                            pblogo.SizeMode    = PictureBoxSizeMode.StretchImage;
                            pblogo.BorderStyle = BorderStyle.Fixed3D;
                            //pictureBox6.SetBounds(650, 400, 80, 80);
                            pblogo.BringToFront();
                            // Add the new control to its parent's controls collection
                            //this.Controls.Add(pictureBox6);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
        private void ExAddImage(object obj)
        {
            ChampImage champImage = obj as ChampImage;

            if (champImage != null)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();

                // Construit la liste des extensions souhaitées
                string text = this.BuildExtensionFormat(champImage);
                openFileDialog.Filter           = ((!string.IsNullOrEmpty(text)) ? text : "All files (*.*)|*.*");
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == true)
                {
                    try
                    {
                        Stream stream;
                        if ((stream = openFileDialog.OpenFile()) != null)
                        {
                            using (stream)
                            {
                                byte[] array = new byte[stream.Length];
                                stream.Read(array, 0, (int)stream.Length);
                                champImage.img.Source = (new ConverterImage().Convert(array, null, null, null) as ImageSource);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }
            }
        }
Example #17
0
        private void toolStripMenuItemModify_Click(object sender, EventArgs e)
        {
            if (ReadOnly)
            {
                return;
            }

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.RestoreDirectory = true;
            //ofd.InitialDirectory = "c:\\";
            openFileDialog1.Filter      = "所有文件 (*.*)|*.*|Word 文档 (*.Doc)|*.Doc";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Stream myStream;
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    FileInfo fi   = new FileInfo(openFileDialog1.FileName);
                    int      len  = Convert.ToInt32(fi.Length);
                    byte[]   data = new byte[len];
                    myStream.Read(data, 0, len);
                    myStream.Close();

                    SelectedDataValue = data;

                    if (this.AssociateControl != null)
                    {
                        this.AssociateControl.SelectedDataValue = openFileDialog1.SafeFileName;
                    }
                }
            }
            openFileDialog1.Dispose();
        }
Example #18
0
        static void openExternalFile(RichTextBox rtbox)
        {
            OpenFileDialog opendi = new OpenFileDialog();

            if (opendi.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (opendi.OpenFile() != null)
                {
                    string fname = opendi.FileName;
                    if (Path.GetExtension(fname) == ".docx")
                    {
                        DocumentCore  dc   = DocumentCore.Load(fname);
                        StringBuilder text = new StringBuilder();

                        foreach (Paragraph par in dc.GetChildElements(true, ElementType.Paragraph))
                        {
                            foreach (Run run in par.GetChildElements(true, ElementType.Run))
                            {
                                text.Append(run.Text);
                            }
                            text.AppendLine();
                            rtbox.Text = text.ToString();
                        }
                    }
                    else
                    {
                        if (Path.GetExtension(fname) == ".txt")
                        {
                            StreamReader sw    = new StreamReader(fname);
                            string       input = sw.ReadToEnd();
                            rtbox.Text = input;
                        }
                    }
                }
            }
        }
Example #19
0
        private void btnBrowsePhoto_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog opFile = new OpenFileDialog();

            opFile.Title  = "Select a Image";
            opFile.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";

            string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\StudentImages\";

            if (Directory.Exists(appPath) == false)
            {
                Directory.CreateDirectory(appPath);
            }

            if (opFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string iName    = opFile.SafeFileName;
                    string filepath = opFile.FileName;

                    File.Copy(filepath, appPath + iName);
                    pictureBox.Image    = new Bitmap(opFile.OpenFile());
                    pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
                    photoPath           = appPath + iName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to open file " + ex.Message);
                }
            }
            else
            {
                opFile.Dispose();
            }
        }
Example #20
0
        private void UploadFileC_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = false;
            dlg.Filter      = Helper.UploadFilter(Helper.enUploadType.Files);

            if ((bool)dlg.ShowDialog())
            {
                Stream file     = dlg.OpenFile();
                string filePath = dlg.SafeFileName;

                this.UploadFileC = Helper.UploadFile(Helper.enUploadType.Files, file, filePath);
                FileToImageIconConverter some = new FileToImageIconConverter(filePath);
                ImageSource imgSource         = some.Icon;
                myFilesList.Add(new MyFiles {
                    FileName = dlg.SafeFileName, FileIcon = imgSource
                });
            }
            else
            {
                MessageBox.Show("File not selected");
            }
        }
Example #21
0
        // The openToolStripMenuItem_Click Method
        // Purpose: opens file explorer to find a file, and then reads the first line of that file, and outputs it in the text box.
        // Parameters: The sending object, and the event arguments
        // Returns: none
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // declares a Stream reference. The Open method returns a Stream reference that we will store in reference variable myStream.
            Stream myStream = null;
            // creates an OpenFileDialogue object.
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //defines the initial directory to use when the File Open dialogue is displayed.
            openFileDialog1.InitialDirectory = "c://";
            //defines the file extensions to show in the file dialogue.
            openFileDialog1.Filter = "text files (*txt)|*txt";
            //displays the File Open dialogue and checks the return value to make sure that this operation worked.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Line 10 opens the file and assigns the reference to the stream object to myStream. If the file did not open for some reason the reference will be null.
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    //creates a StreamReader object using the Stream myStream as its parameter.
                    StreamReader data = new StreamReader(myStream);
                    //reads one line of data from the file and stores it in the Text property of the Control TextBox object. Here I have named that TextBox object textBox.
                    Control.Text = data.ReadLine( );
                }
            }
        }
Example #22
0
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title  = "Open Image";
            dlg.Filter = "All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Bitmap imageToPrint = new Bitmap(dlg.OpenFile());
                    pictureBox1.Image = imageToPrint;

                    //Refresh();
                    //userAdjust();
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "Erreur", MessageBoxButtons.OK);
                }
            }
            dlg.Dispose();
        }
Example #23
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            Stream myStream;

            ofd.Filter = "All Files(*.*)|*.*|Text Files(*.txt)|*.txt";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = ofd.OpenFile()) != null)
                {
                    FileAddress = ofd.FileName;
                    string   strfilename = ofd.FileName;
                    FileInfo fileInfo    = new FileInfo(strfilename);
                    FileExtension = fileInfo.Extension;

                    newpage(fileInfo.Name);
                    changeExt(FileExtension);
                    string filetext = File.ReadAllText(strfilename);
                    GetRichTextBox().Text = filetext;
                }
                myStream.Close();
            }
        }
Example #24
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Filter           = "Demo files|*.dem",
                RestoreDirectory = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                messageList.Items.Clear();

                Stream f = ofd.OpenFile();
                _currentFile = new DemoFile(f);
                f.Close();

                foreach (var msg in _currentFile.Messages)
                {
                    messageList.Items.Add(new DemoMessageItem(msg));
                }
            }

            propertiesToolStripMenuItem.Enabled = true;
        }
Example #25
0
        private void LoadImg_btn_Click(object sender, EventArgs e)
        //Загружаем с диска изображение в бокс.
        {
            Bitmap         image;
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

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

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            image = new Bitmap(openFileDialog1.FileName);
//                            pictureBox3.Width = image.Width;
//                            pictureBox3.Height = image.Height;
                            LoadImg_box.Image = image;
                            LoadImg_box.Invalidate();   // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    DialogResult rezult = MessageBox.Show("Невозможно открыть выбранный файл",
                                                          "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Example #26
0
        private void BtnSelectFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                InitialDirectory = @"D:\Network\Client",
                Title            = "Browse Text Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "txt files (*.txt)|*.txt",
                FilterIndex      = 1,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true,
                AddExtension    = true
            };

            if (openFileDialog.ShowDialog() == true)
            {
                txtPath.Text = openFileDialog.FileName;
                filePath     = openFileDialog.InitialDirectory;
                fileName     = Path.GetFileNameWithoutExtension(openFileDialog.FileName);

                var fileStream = openFileDialog.OpenFile();

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    fileContent = reader.ReadToEnd();
                }
                txtClient.Text = fileContent;
                ExecuteClient();
            }
        }
Example #27
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp,*.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Stream myStream;
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            pictureBox1.Image = new Bitmap(openFileDialog1.FileName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Example #28
0
        private void button4_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "G:\\PROYECTO GERARDO\\Encuestas";

            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)
                        {
                            // MessageBox.Show(openFileDialog1.FileName.ToString());// Insert code to read the stream here.

                            destino_archivo     = openFileDialog1.FileName.ToString();
                            txt_direxml.Text    = destino_archivo;
                            txt_direccarpe.Text = Path.GetDirectoryName(openFileDialog1.FileName) + @"\";
                            //MessageBox.Show(destino);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
                //string carpeta =txt_direccarpe.Text+ "Encuesta, dia ";
                //MessageBox.Show(carpeta);
            }
        }
Example #29
0
        private void button_Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd    = null;
            Stream         stream = null;

            ofd = FileOpen();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                label_Title.Text = Path.GetFileName(ofd.FileName.ToString());
                stream           = ofd.OpenFile();
                if (stream != null)
                {
                    StreamReader sr = new StreamReader(stream);
                    richTextBox_Memo.Text = sr.ReadToEnd();
                    sr.Close();
                    stream.Close();
                }                       // TODO:文字コードを勝手に決めてくれるようにしたい。
            }
            else
            {
                ofd.Reset();
                ofd.Dispose();
            }
        }
Example #30
0
        public static DialogResult OpenSSOImportFile(out string applicationFileName, out string encryptedText, ApplicationScopeNode callingNode)
        {
            DialogResult dialogResult = DialogResult.None;

            applicationFileName = string.Empty;
            encryptedText       = string.Empty;
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.CheckFileExists = true;
                openFileDialog.CheckPathExists = true;
                openFileDialog.DefaultExt      = "*.sso";
                openFileDialog.Filter          = "SSO Extract files (*.sso)|*.sso|All files (*.*)|*.*";
                openFileDialog.Title           = "Import SSO Application";
                dialogResult = callingNode.SnapIn.Console.ShowDialog(openFileDialog);
                if (dialogResult == DialogResult.Cancel)
                {
                    return(dialogResult);
                }
                applicationFileName = Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                StreamReader streamReader = new StreamReader(openFileDialog.OpenFile());
                try
                {
                    encryptedText = streamReader.ReadToEnd();
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("SSO MMC SnapIn - ImportSSOApplication \r\n", ex.ToString());
                    throw;
                }
                finally
                {
                    streamReader.Dispose();
                }
            }
            return(dialogResult);
        }
Example #31
0
        private void button1_Click(object sender, EventArgs e)
        {
            stop = true;
            reses.Clear();
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.RestoreDirectory = true;
            dialog.Filter           = "HTML|*.html;*.htm";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                stop = false;
                System.IO.Stream       stream = dialog.OpenFile();
                System.IO.StreamReader sr     = new System.IO.StreamReader(stream);
                string str = sr.ReadToEnd();
                sr.Close();
                stream.Close();

                foreach (string s in str.Split('\n'))
                {
                    if (s.StartsWith("<dt>"))
                    {
                        int      dateStart = s.IndexOf(":") + 1;
                        int      dateEnd   = s.IndexOf("ID");
                        string   dateStr   = s.Substring(dateStart, dateEnd - dateStart);
                        DateTime date      = DateTime.Parse(dateStr);
                        string   res       = s.Substring(s.IndexOf("<dd>") + 4);
                        res = res.Replace("<br>", "\n");
                        ResWriter rw = new ResWriter(date, res);
                        reses.Add(rw);
                    }
                }
                Task task = new Task(writeAction);
                task.Start();
            }
        }
Example #32
0
        public void Open()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Playlist files (*.m3u)|*.m3u|All files (*.*)|*.*";
            openFileDialog1.Title  = "Open Playlist";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "")
            {
                Clear();

                M3uPlaylist playlist = new M3uPlaylist
                {
                    IsExtended = true
                };

                M3uContent content = new M3uContent();

                using (System.IO.FileStream fs = (System.IO.FileStream)openFileDialog1.OpenFile())
                {
                    playlist = content.GetFromStream(fs);

                    // Remove final null char at end of last entry
                    playlist.PlaylistEntries.Last().Path = playlist.PlaylistEntries.Last().Path.Substring(0, playlist.PlaylistEntries.Last().Path.Length - 1);

                    Files = new ObservableCollection <PlaylistEntry>();
                    foreach (M3uPlaylistEntry file in playlist.PlaylistEntries)
                    {
                        Files.Add(new PlaylistEntry(new Song(file.Path)));
                    }
                }

                playlist = null;
            }
        }
Example #33
0
        private void Open(object obj)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "Docx files|*.docx|Rtf files|*.rtf|Html files|*.html|Text files|*.txt|All files (*.*)|*.*";
            dialog.FilterIndex = 1;
            if (dialog.ShowDialog() == true)
            {
                string extension = Path.GetExtension(dialog.FileName);
                IFormatProvider <RadFlowDocument> provider = this.providers
                                                             .FirstOrDefault(p => p.SupportedExtensions
                                                                             .Any(e => string.Compare(extension, e, StringComparison.InvariantCultureIgnoreCase) == 0));

                if (provider != null)
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                        try
                        {
                            this.Document = provider.Import(stream);
                            this.FileName = Path.GetFileName(dialog.FileName);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Could not open file.");
                            this.Document = null;
                            this.FileName = null;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Could not open file.");
                }
            }
        }
Example #34
0
        //打开文件
        private void openButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "文本文件 (*.txt)|*.txt";
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filePath = openFileDialog1.FileName;

                var fileStream = openFileDialog1.OpenFile();

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    string fileContent = reader.ReadToEnd();

                    if (fileContent.Length > 0)
                    {
                        textBox1.Text = fileContent; // 显示内容
                    }
                }
            }
        }
Example #35
0
    public void Wczytaj()
    {
        OpenFileDialog plik = new OpenFileDialog();
        plik.InitialDirectory = ".";
        plik.FileName = "";
        plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
        plik.FilterIndex = 1;
        plik.RestoreDirectory = true;

        if (plik.ShowDialog() == DialogResult.OK)
        {
            Stream plik_stream=plik.OpenFile();
            kalendarz.Wczytaj(plik_stream);
            plik_stream.Flush();
            plik_stream.Close();
        }
    }
Example #36
0
        private void button1_Click_1(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)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error:\n" + ex.Message.ToString());
                }
            }
        }
Example #37
0
    public void Wczytaj()
    {
        kalendarz = new Kalendarz();

        otwórz_plik = new OpenFileDialog();
        otwórz_plik.InitialDirectory = "c:\\";
        otwórz_plik.FileName = "";
        otwórz_plik.Filter = "pliki Kalendarza (*.kalen)|*.kalen|All files (*.*)|*.*";
        otwórz_plik.FilterIndex = 2;
        otwórz_plik.RestoreDirectory = true;

        if (otwórz_plik.ShowDialog() == DialogResult.OK)
        {
            Stream plik = otwórz_plik.OpenFile();
            kalendarz.Wczytaj(plik);
            plik.Flush();
            plik.Close();
        }
    }
Example #38
0
        private void Open()
        {
            System.IO.Stream stream;
            OpenFileDialog   dialog;

            dialog = new OpenFileDialog();
            dialog.Filter = "XML files (*.xml)|*.xml";
            dialog.FilterIndex = 1;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK) {
                if ((stream = dialog.OpenFile()) != null) {
                    _scene.Reset ();
                    _doc.Load (stream);
                    stream.Close ();
                }
            }
        }
Example #39
0
        private void FileOpen()
        {
            DefaultSettings settings = DefaultSettings.Instance;

            Stream myStream;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = settings.DefaultTemplateDirectory;
            openFileDialog.Filter = PROJECT_FILE_TYPES + TemplateEditor.FILE_TYPES;
            openFileDialog.FilterIndex = TemplateEditor.DEFAULT_OPEN_FILE_TYPE_INDEX + 1;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                myStream = openFileDialog.OpenFile();
                if (null != myStream)
                {
                    myStream.Close();

                    foreach (string filename in openFileDialog.FileNames)
                    {
                        int extindex = filename.LastIndexOf(".");
                        if (extindex >= 0)
                        {
                            FileInfo f = new FileInfo(filename);
                            if (f.Exists)
                            {
                                AddRecentFile(f.FullName);

                                string ext = filename.Substring(extindex);
                                bool validProjectExt = false;
                                foreach (string vpe in validProjectExtentions)
                                {
                                    if (vpe == ext)
                                        validProjectExt = true;
                                }

                                if (validProjectExt)
                                {
                                    this.OpenProjectEditor(filename);
                                }
                                else
                                {
                                    this.OpenTemplateEditor(filename);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #40
0
        private void bt_browse_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            Stream myStream = null;

            openFileDialog1.InitialDirectory = path + "\\media\\BasicHomeBG";
            openFileDialog1.Filter = "PNG files (*.png)|*.png|JPG files (*.jpg)|*.jpg";
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            if (System.IO.Directory.Exists(path))
                            {
                                System.IO.File.Copy(openFileDialog1.FileName, path + "\\media\\BasicHomeBG\\" + openFileDialog1.SafeFileName, true);
                            }
                            new_bgimage.Text = openFileDialog1.SafeFileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }

            }
        }
Example #41
0
        /// <summary>
        /// Uncompress (gzip) and deserialize a file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiLoadResults_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var browser = new OpenFileDialog();

            browser.DefaultExt = "findResults";
            browser.Filter = "find results|*.findResults|All Files|*.*";
            browser.Title = "Open find results";

            if (browser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var ser = new XmlSerializer(typeof(FindResults));

                using (var file = browser.OpenFile())
                using(var gzip = new GZipStream(file, CompressionMode.Decompress))
                    findResults = (FindResults)ser.Deserialize(gzip);

                gridControl1.DataSource = findResults.Found;
                uiFoundCount.Caption = string.Format("Found {0} items in {1} files", findResults.Found.Count, findResults.FilesSearched);
            }
        }
Example #42
0
        internal static void manualInstallMod()
        {
            if (isInstalling)
            {
                notifier.Notify(NotificationType.Warning, "Already downloading a mod", "Please try again after a few seconds.");
                return;
            }
            isInstalling = true;

            using (var dlg = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt = "zip",
                Filter = "Zip Files|*.zip",
                FilterIndex = 1,
                Multiselect = false,
                Title = "Choose the mod zip to install"
            })
            {
                //user pressed ok
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    //open the file in a stream
                    using (var fileStream = dlg.OpenFile())
                    {
                        ZipFile zip = new ZipFile(fileStream);

                        //check integrity
                        if (zip.TestArchive(true))
                        {
                            //look for the map file. It contains the mod name
                            ZipEntry map = zip.Cast<ZipEntry>().FirstOrDefault(a => a.Name.ToLower().EndsWith(".bsp"));

                            if (map != null)
                            {
                                //look for the version file
                                int entry = zip.FindEntry("addoninfo.txt", true);
                                if (entry >= 0)
                                {
                                    string allText = string.Empty;

                                    using (var infoStream = new StreamReader(zip.GetInputStream(entry)))
                                        allText = infoStream.ReadToEnd();

                                    string version = modController.ReadAddonVersion(allText);

                                    if (!string.IsNullOrEmpty(version))
                                    {
                                        Version v = new Version(version);
                                        string name = Path.GetFileNameWithoutExtension(map.Name).ToLower();

                                        //check if this same mod is already installed and if it needs an update
                                        if (modController.clientMods.Any(
                                            a => a.name.ToLower().Equals(name) && new Version(a.version) >= v))
                                        {
                                            MessageBox.Show("The mod you are trying to install is already installed or outdated.", "Mod Manual Install",
                                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                        else
                                        {
                                            string targetDir = Path.Combine(d2mpDir, name);
                                            if (Directory.Exists(targetDir))
                                                Directory.Delete(targetDir, true);
                                            //Make the dir again
                                            Directory.CreateDirectory(targetDir);

                                            if (UnzipWithTemp(null, fileStream, targetDir))
                                            {
                                                refreshMods();
                                                log.Info("Mod manually installed!");
                                                notifier.Notify(NotificationType.Success, "Mod installed", "The following mod has been installed successfully: " + name);

                                                var mod = new ClientMod() {name = name, version = v.ToString()};
                                                var msg = new OnInstalledMod() {Mod = mod};

                                                Send(JObject.FromObject(msg).ToString(Formatting.None));

                                                var existing = modController.clientMods.FirstOrDefault(m => m.name == mod.name);
                                                if (existing != null) modController.clientMods.Remove(existing);
                                                
                                                modController.clientMods.Add(mod);
                                            }
                                            else
                                            {
                                                MessageBox.Show("The mod could not be installed. Read the log file for details.", "Mod Manual Install",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Could not read the mod version from the zip file.", "Mod Manual Install",
                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("No mod info was found in the zip file.", "Mod Manual Install",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                MessageBox.Show("No mod map was found in the zip file.", "Mod Manual Install",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("The zip file you selected seems to be invalid.", "Mod Manual Install",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }

            isInstalling = false;
        }
    /// <summary>
    /// This is the worker method that executes when the user clicks the GO button.
    /// It illustrates the workflow that would need to take place in an actual application.
    /// </summary>
    public static void AuthorizeAndUpload()
    {
        // First, create a reference to the service you wish to use.
        // For this app, it will be the Drive service. But it could be Tasks, Calendar, etc.
        // The CreateAuthenticator method is passed to the service which will use that when it is time to authenticate
        // the calls going to the service.
        _service = new DriveService(CreateAuthenticator());

        // Open a dialog box for the user to pick a file.
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.AddExtension = true;
        dialog.DefaultExt = ".txt";
        dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
        dialog.Multiselect = false;
        dialog.ShowDialog();

        File body = new File();
        body.Title = System.IO.Path.GetFileName(dialog.FileName);
        body.Description = "A test document";
        body.MimeType = "text/plain";

        System.IO.Stream fileStream = dialog.OpenFile();
        byte[] byteArray = new byte[fileStream.Length];
        fileStream.Read(byteArray, 0, (int)fileStream.Length);

        System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

        // Get a listing of the existing files...
        List<File> fileList = GoogleDrive.Util.Utilities.RetrieveAllFiles(_service);

        // Set a flag to keep track of whether the file already exists in the drive
        bool fileExists = false;

        foreach (File item in fileList)
        {
            if (item.Title == body.Title)
            {
                // File exists in the drive already!
                fileExists = true;
                DialogResult result = MessageBox.Show("The file you picked already exists in your Google Drive. Do you wish to overwrite it?", "Confirmation", System.Windows.Forms.MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {

                    // Yes... overwrite the file
                    GoogleDrive.Util.Utilities.UpdateFile(_service, item.Id, item.Title, item.Description, item.MimeType, dialog.FileName, true);
                }

                else if (result == DialogResult.No)
                {

                    // MessageBoxResult.No code here
                    GoogleDrive.Util.Utilities.InsertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
                }

                else
                {

                    // MessageBoxResult.Cancel code here
                    return;
                }
                break;
            }
        }

        // Check to see if the file existed. If not, it is a new file and must be uploaded.
        if (!fileExists)
        {
            GoogleDrive.Util.Utilities.InsertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
        }

        System.Windows.Forms.MessageBox.Show("Upload Complete");
    }