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


C# OpenFileDialog.OpenFiles方法代码示例

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


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

示例1: TryLoadImage

        public ImageViewModel TryLoadImage()
        {
            OpenFileDialog fileDialog = new OpenFileDialog()
                                        {
                                            CheckFileExists = true,
                                            CheckPathExists = true,
                                            Multiselect = true,
                                            Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png"
            };

            Func<string, bool> isValidFile = file =>
                                             {
                                                 string[] extensions =
                                                 {
                                                     ".jpg",
                                                     ".png",
                                                     ".jpeg"
                                                 };

                                                 string ext = Path.GetExtension(file);
                                                 return extensions.Contains(ext);
                                             };

            fileDialog.FileOk += (sender, args) =>
                                 {
                                     if (!fileDialog.FileNames.All(isValidFile))
                                         args.Cancel = true;
                                 };

            bool? dialogResult = fileDialog.ShowDialog();
            if (dialogResult.HasValue && dialogResult.Value)
            {
                try
                {
                    Stream[] files = fileDialog.OpenFiles();
                    for (int i = 0; i < fileDialog.FileNames.Length; i++)
                    {
                        string filePath = fileDialog.FileNames[i];
                        Stream file = files[i];
                        byte[] fileData = null;

                        using (var stream = new MemoryStream())
                        {
                            file.CopyTo(stream);
                            fileData = stream.ToArray();
                        }

                        ImageViewModel viewModel = new ImageViewModel(0, Path.GetFileName(filePath), fileData);

                        return viewModel;
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return null;
        }
开发者ID:kobyb1988,项目名称:PhotoBox,代码行数:59,代码来源:ImageLoadService.cs

示例2: AddItems

        /// <summary>
        /// Adds the items.
        /// </summary>
        /// <param name="files">The files.</param>
        private void AddItems(OpenFileDialog files)
        {
            Stream[] fileStreams = files.OpenFiles();
            for (int index = 0; index < files.FileNames.Length; index++)
            {
                Gallery gallery = ((Gallery)galleryListBox.SelectedItem);

                ClientImage image = new ClientImage
                                        {
                                            ImageName = TruncatePath(files.FileNames[index]),
                                            GalleryName = gallery.Name,
                                            GalleryId = gallery.GalleryID,
                                            PhotoBytes = GetByteArrayFromStream(fileStreams[index])

                                         };

                uploadListBox.Items.Add(image);
            }
        }
开发者ID:chuckconway,项目名称:chucksoft-gallery,代码行数:23,代码来源:Main.xaml.cs

示例3: OpenFile_Click

        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            filePath.Clear(); textBox_Files.Text = "";

            StringBuilder sb = new StringBuilder();
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = true;
            dialog.Filter = "Text Files (.txt)|*.txt";
            dialog.ShowDialog();

            if (dialog.OpenFiles() != null)
            {
                filePath.AddRange(dialog.FileNames);
                sb.AppendLine("(" + filePath.Count + "шт.) ");

                for (int i = 0; i < filePath.Count; i++)
                {
                    sb.AppendLine(System.IO.Path.GetFileName(filePath[i]));
                }

                textBox_Files.Text = sb.ToString();
            }
        }
开发者ID:AlexKrainov,项目名称:WiFi,代码行数:24,代码来源:MainWindow.xaml.cs

示例4: AddPatterns

        private void AddPatterns()
        {
            OpenFileDialog fileDialog = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                Multiselect = true,
                Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg"
            };

            Func<string, bool> isValidFile = file =>
            {
                string[] extensions =
                {
                    ".png",
                    ".jpeg",
                    ".jpg"
                };

                string ext = Path.GetExtension(file);
                return extensions.Contains(ext);
            };

            fileDialog.FileOk += (sender, args) =>
            {
                if (!fileDialog.FileNames.All(isValidFile))
                    args.Cancel = true;
            };

            bool? dialogResult = fileDialog.ShowDialog();
            if (dialogResult.HasValue && dialogResult.Value)
            {
                try
                {
                    Stream[] files = fileDialog.OpenFiles();
                    for (int i = 0; i < fileDialog.FileNames.Length; i++)
                    {
                        string filePath = fileDialog.FileNames[i];
                        Stream file = files[i];
                        byte[] fileData = null;

                        using (var stream = new MemoryStream())
                        {
                            file.CopyTo(stream);
                            fileData = stream.ToArray();
                        }

                        CheckablePatternDataViewModel viewModel = new PatternDataViewModel(Path.GetFileName(filePath), Pattern.PatternType, fileData)
                            .ToCheckable(ItemState.Added);

                        Children.Add(viewModel);
                    }
                }
                catch (Exception ex)
                {
                }

                CheckItem();
            }
        }
开发者ID:kobyb1988,项目名称:PhotoBox,代码行数:60,代码来源:PatternManageViewModel.cs


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