当前位置: 首页>>代码示例>>C#>>正文


C# OpenFileDialog.OpenFile方法代码示例

本文整理汇总了C#中System.Windows.Forms.OpenFileDialog.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.OpenFile方法的具体用法?C# OpenFileDialog.OpenFile怎么用?C# OpenFileDialog.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.OpenFileDialog的用法示例。


在下文中一共展示了OpenFileDialog.OpenFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: _ouvrir

        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;
        }
开发者ID:joanny,项目名称:Lecteur_mp3,代码行数:60,代码来源:ControleLecture.cs

示例2: button1_Click

        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);
                }
            }
        }
开发者ID:kaxaru,项目名称:Euler,代码行数:25,代码来源:Form1.cs

示例3: SelectFileToAdjuct

 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;
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:31,代码来源:AdjunctEditCommand.cs

示例4: button2_Click

        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);
                }
            }
        }
开发者ID:hanjae,项目名称:VISPJ,代码行数:32,代码来源:Form1.cs

示例5: btnLoadCsvToPool_Click

        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();
                }
            }
        }
开发者ID:fcbaconguis,项目名称:c,代码行数:29,代码来源:Form1.cs

示例6: showDialog

 public static void showDialog()
 {
     var d = new OpenFileDialog();
     if(d.ShowDialog() == DialogResult.OK){
         Console.WriteLine(d.OpenFile().ToString());
     }
 }
开发者ID:MrFlark,项目名称:CSharp,代码行数:7,代码来源:Test.cs

示例7: GetFilePath

        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;
        }
开发者ID:theVitaliy,项目名称:Garmash,代码行数:30,代码来源:FilePathGeter.cs

示例8: openToolStripMenuItem_Click

        // 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);
                }
            }
        }
开发者ID:kacecode,项目名称:SchoolWork,代码行数:34,代码来源:Form1.cs

示例9: pbImage_DoubleClick

 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);
         }
     }
 }
开发者ID:wpscott,项目名称:csis3275,代码行数:26,代码来源:ProductEdit.cs

示例10: btnImportFile_Click

 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);
     }
 }
开发者ID:gnllk,项目名称:RedisClient,代码行数:26,代码来源:EditForm.cs

示例11: btnOpenXml_Click

        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);

            }
        }
开发者ID:vikinger,项目名称:ibsys2tool,代码行数:35,代码来源:UserControl_Prognose.cs

示例12: btnProcurar_Click

        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);
                }
            }
        }
开发者ID:mppassos,项目名称:Projetos-C--,代码行数:29,代码来源:Form1.cs

示例13: fileLoad

        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;
                }
            }
        }
开发者ID:uiloon,项目名称:CS_WindowTest,代码行数:31,代码来源:Form2.cs

示例14: buttonEscogerImagen_Click

        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);
                }
            }
        }
开发者ID:pablovargan,项目名称:winforms-ooh4ria,代码行数:30,代码来源:AltaProducto.cs

示例15: openToolStripMenuItem_Click

 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);
         }
     }
 }
开发者ID:Helixanon,项目名称:labs,代码行数:26,代码来源:Form1.cs


注:本文中的System.Windows.Forms.OpenFileDialog.OpenFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。