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


C# OpenFileDialog.OpenFile方法代码示例

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


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

示例1: ButtonBase_OnClick

        private void ButtonBase_OnClick (object sender, RoutedEventArgs e)
        {
            try
            {
                 var dig = new OpenFileDialog();
                dig.Title = "选择文件";
                dig.Filter = "rtf文件|*.rtf";
                dig.RestoreDirectory = true;
                if(dig.ShowDialog() == true)
                {
                    using(var ms = dig.OpenFile())
                    {
                         var bytes = new byte[ms.Length];
                         ms.Read(bytes, 0, (int)ms.Length);
                       var str =  Encoding.UTF8.GetString(bytes);
                        this.RtfText  = str;
                    }
                
                }
            } catch(Exception c)
            {
                MessageBox.Show(c.Message);

            }
          
        }
开发者ID:powerhai,项目名称:Jinchen,代码行数:26,代码来源:RichTextEditor.xaml.cs

示例2: SelectFileButton_Click

        private void SelectFileButton_Click(object sender, RoutedEventArgs e)
        {
            // TODO 1 open file dialog and choose directoy to start
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.InitialDirectory = "C:\\Users\\Jason\\Downloads";

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    using (StreamReader reader = new StreamReader(dialog.OpenFile()))
                    {
                        string line;
                        StringBuilder sb = new StringBuilder();

                        while ((line = reader.ReadLine()) != null)
                        {
                            sb.Append(line).Append("...").Append(Environment.NewLine);
                        }

                        ContentTb.Text = sb.ToString();

                    }
                }
                catch (IOException ex)
                {
                    StatusLb.Content = ex.Message;
                }

            }

            // TODO 2 if the user selected a file display file/dir name and text
        }
开发者ID:Hummingdroid,项目名称:Personal-CSharp-Projects-And-Practices,代码行数:33,代码来源:MainWindow.xaml.cs

示例3: LoadLibButton_Click

        private void LoadLibButton_Click(object sender, RoutedEventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Dynamically Linked Library|*.dll";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == true)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            LibraryPath = openFileDialog1.FileName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
开发者ID:sneddy,项目名称:TestSportClient,代码行数:28,代码来源:MainFormWindow.xaml.cs

示例4: LoadDocumentToInsert

        private RadDocument LoadDocumentToInsert()
        {
            RadDocument document = null;

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Word Documents (*.docx)|*.docx|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == true)
            {
                string extension;
#if SILVERLIGHT
                extension = ofd.File.Extension.ToLower();
#else
                extension = Path.GetExtension(ofd.SafeFileName).ToLower();
#endif

                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

                Stream stream;
#if SILVERLIGHT
                stream = ofd.File.OpenRead();
#else
                stream = ofd.OpenFile();
#endif
                using (stream)
                {
                    document = provider.Import(stream);
                }
            }

            return document;
        }
开发者ID:Motaz-Al-Zoubi,项目名称:xaml-sdk,代码行数:32,代码来源:MainPage.xaml.cs

示例5: GetLayout

        public override InteriorField[,] GetLayout()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.DefaultExt = "txt";
            DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
            openFileDialog.InitialDirectory = (currentDir.EnumerateDirectories().FirstOrDefault(d => d.Name == DataSubdirName) ?? currentDir).FullName;
            if (openFileDialog.ShowDialog().GetValueOrDefault())
            {
                this.LayoutIdentifier = openFileDialog.FileName;
                using (StreamReader readLines = new StreamReader(openFileDialog.OpenFile()))
                {
                    List<List<InteriorField>> layout = readLines
                        .ReadToEnd()
                        .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s
                            .Select(c => this.CreateField(c)).ToList()).ToList();

                    int columnsCount = layout.Max(l => l.Count);
                    InteriorField[,] result = new InteriorField[layout.Count, columnsCount];
                    for (int row = 0; row < layout.Count; row++)
                    {
                        for (int col = 0; col < layout[row].Count; col++)
                        {
                            result[row, col] = layout[row][col];
                        }
                    }
                    return result;
                }
            }
            else
            {
                return null;
            }
        }
开发者ID:blattodephobia,项目名称:ExperianOfficeArangement,代码行数:34,代码来源:FileLoadInteriorLayoutFactory.cs

示例6: ReadFile

        public static string ReadFile(this SerialPort com)
        {
            Stream input = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = Environment.CurrentDirectory;
            openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == true)
            {
                try
                {
                    if ((input = openFileDialog.OpenFile()) != null)
                        using (StreamReader sr = new StreamReader(input))
                        {
                            string text = sr.ReadToEnd();
                            byte [] buffer = ASCIIEncoding.ASCII.GetBytes(text);
                            com.Write(buffer, 0, buffer.Length);
                            return string.Format("File {0}: \n{1}\n", openFileDialog.FileName, text);
                        }
                }
                catch (Exception ex)
                {
                    return "Error: Could not read file from disk. Original error: " + ex.Message;
                }
            }
            return "File isn`t selected.\n";
        }
开发者ID:rukpet,项目名称:COM-Port,代码行数:30,代码来源:COM_PortHelper.cs

示例7: ImportDB_Click

 private void ImportDB_Click(object sender, RoutedEventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.DefaultExt = ".db";
     dialog.Filter = "DataBase(.db)|*.db";
     bool? res = dialog.ShowDialog();
     if (res.HasValue && res.Value) {
         DBConnection.ins().closeDb();
         Stream stream = dialog.OpenFile();
         FileStream fs = new FileStream(DBConnection.path, FileMode.OpenOrCreate);
         byte[] buffer = new byte[1024];
         int count = 0;
         while ((count = stream.Read(buffer, 0, 1024)) > 0)
         {
             fs.Write(buffer, 0, count);
         }
         stream.Close();
         fs.Close();
         MessageBoxResult result = MessageBox.Show("匯入資料庫需重開系統", "確認視窗", MessageBoxButton.OK, MessageBoxImage.Information);
         if (result == MessageBoxResult.OK) {
             System.Diagnostics.Process.Start(System.Windows.Application.ResourceAssembly.Location);
             System.Windows.Application.Current.Shutdown();
         }
     }
 }
开发者ID:kimchen,项目名称:SalonManager,代码行数:25,代码来源:MainWindow.xaml.cs

示例8: OpenFile

        public Stream OpenFile(string defaultExtension, string filter)
        {
            var fd = new OpenFileDialog { DefaultExt = defaultExtension, Filter = filter };

            var result = fd.ShowDialog();

            return result != null && result.Value ? fd.OpenFile() : null;
        }
开发者ID:mikecole,项目名称:ChocolateyGUI,代码行数:8,代码来源:PersistenceService.cs

示例9: OpenBrowserDialog

        public string OpenBrowserDialog(string defaultPath)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = defaultPath;

            ofd.OpenFile();

            return ofd.FileName;
        }
开发者ID:rhwilson1971,项目名称:PeopleManager,代码行数:10,代码来源:FileBrowserService.cs

示例10: ChooseButton_OnClick

        private void ChooseButton_OnClick(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "(*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png";

            if (dlg.ShowDialog() == true)
            {
                this.ViewModel.BinaryData = dlg.OpenFile().ToArray();
            }
        }
开发者ID:Cologler,项目名称:JRYVideo,代码行数:11,代码来源:CoverEditorWindow.xaml.cs

示例11: openfile

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Stream openfile()
        {
            var dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == true)
            {

                return dialog.OpenFile();
            }
            return null;
        }
开发者ID:kulubaev,项目名称:demo,代码行数:15,代码来源:filedialogservice.cs

示例12: ChangeStyleCommand_Executed

 private void ChangeStyleCommand_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     OpenFileDialog dlg = new OpenFileDialog();
     dlg.Filter = "XAML Styles (*.xaml)|*.xaml";
     dlg.InitialDirectory = Environment.CurrentDirectory;
     if (dlg.ShowDialog().Value)
     {
         using (Stream fs = dlg.OpenFile())
         {
             LoadStyle(fs);
         }
     }
 }
开发者ID:itsbth,项目名称:DoIt,代码行数:13,代码来源:MainWindow.xaml.cs

示例13: LoadASM

 private void LoadASM(object sender, RoutedEventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.FileName = "";
     dialog.DefaultExt = ".asm";
     dialog.Filter = "Assembly (.asm)|*.asm|Text Files (.txt)|*.txt";
     bool? res = dialog.ShowDialog();
     if(res == true)
     {
         StreamReader f = new StreamReader(dialog.OpenFile());
         Assembly.Text = f.ReadToEnd();
         f.Close();
     }
 }
开发者ID:Plasmarobo,项目名称:GAPP,代码行数:14,代码来源:GBAssembler.xaml.cs

示例14: uploadBtn_Click

        private void uploadBtn_Click(object sender, RoutedEventArgs e)
        {
            var fileDlg = new OpenFileDialog();

            if (fileDlg.ShowDialog() == true)
            {
                new FileInfo(fileDlg.FileName);
                using (Stream s = fileDlg.OpenFile())
                {
                    attachTxtBox.Text = fileDlg.FileName;
                }
            }

        }
开发者ID:afifda,项目名称:CIFData.Mandiri,代码行数:14,代码来源:MainWindow.xaml.cs

示例15: Open

        public static void Open(string filePath, ref ObservableCollection<Achievement> achievements)
        {
            var openDialog = new OpenFileDialog {Filter = "Data files (*.save)|*.save;"};
            var ok = openDialog.ShowDialog();

            if (!ok.Value) return;

            _currentFilePath = openDialog.FileName;
            using (var fs = openDialog.OpenFile())
            {
                var serializer = new XmlSerializer(typeof(ObservableCollection<Achievement>));
                achievements = (ObservableCollection<Achievement>)serializer.Deserialize(fs);
            }
        }
开发者ID:tiddan,项目名称:AchievementManager,代码行数:14,代码来源:DataStore.cs


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