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


C# Controls.OpenFileDialog类代码示例

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


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

示例1: btnAdd_Click

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = GlobalMembers.SupportedFileType;
            dlg.FilterIndex = 1;
            dlg.Multiselect = false;

            if ((bool)dlg.ShowDialog())
            {
                foreach (UploadItem ui in listUploadItems.Items)
                {
                    if (ui.ItemInfo.Name == dlg.File.Name)
                        return;
                }

                int itemId = listUploadItems.Items.Count;
                if (itemId < GlobalMembers.MaxThread)
                {
                    UploadItem item = new UploadItem(dlg.File, itemId);
                    listUploadItems.Items.Add(item);

                    if (IsSignIn && !btnUpload.IsEnabled)
                        btnUpload.IsEnabled = true;
                }
            }
        }
开发者ID:nimatra,项目名称:LiveSDK,代码行数:26,代码来源:MainPage.xaml.cs

示例2: button1_Click

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog nekaj = new OpenFileDialog();

            bool? nekaj2 = nekaj.ShowDialog();
            if (nekaj2 == true)
            {

                using (FileStream fs = nekaj.File.OpenRead())
                {
                    byte[] buffer = new byte[(int)fs.Length];
                    fs.Read(buffer, 0, (int)fs.Length);
                    char[] niz = new char[buffer.Length];

                    for (int i = 0; i < buffer.Length; i++)
                        niz[i] = (char)buffer[i];

                    IsolatedStorageFile isf =
            IsolatedStorageFile.GetUserStoreForApplication();
                    IsolatedStorageFileStream tok = new IsolatedStorageFileStream("test.txt", FileMode.Create, isf);
                    tok.Write(buffer, 0, buffer.Length);

                    tok.Close();
                }
            }
            else MessageBox.Show("Preklicano");
        }
开发者ID:AndrejSlapnik,项目名称:FERI-Praktikum,代码行数:27,代码来源:MainPage.xaml.cs

示例3: OpenFile

        private void OpenFile(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter = "图片 (*.jpg)|*.jpg",
                Multiselect = false  //不允许多选
            };
            bool chooseFile = dialog.ShowDialog() == true;
            if (!chooseFile) { return; }
            cover.CanSee = true;

            Stream tStream = dialog.File.OpenRead();
            byte[] t = new byte[tStream.Length];
            tStream.Read(t, 0, (int)tStream.Length);
            PicServiceClient client = new PicServiceClient();
            client.UploadCompleted += (_sender, _e) =>
                {

                    State = _e.Result;
                    cover.CanSee = false;
                    hadOpenFile = true;
                };
            client.UploadAsync(t);

            Stream ts = new MemoryStream(t);
            BitmapImage bi = new BitmapImage();
            bi.SetSource(ts);
            img.ImageSource = bi;
        }
开发者ID:returnanapple,项目名称:Client,代码行数:29,代码来源:UploadControl.xaml.cs

示例4: OnClick

        private void OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Multiselect = true;
            if (dlg.ShowDialog() == true)
            {
                if (MessageBox.Show("Are you sure you want to upload the selected files?", "Confirm Upload", MessageBoxButton.OK) == MessageBoxResult.OK)
                {

                    //string cmd = "test";
                    //string msg = "test";

                    //string url = "https://secure.veshter.com/static/bulkupload/test/dummyack.php";
                    string url = "http://localhost:7777/BulkUploaderTestPage.html";

                    VESHTER.HttpHelper helper = new VESHTER.HttpHelper(url);//, "POST",
            //new KeyValuePair<string, string>("authKey", "key"),
            //new KeyValuePair<string, string>("cmd", cmd.ToString()),
            //new KeyValuePair<string, string>("msg", msg));
                    //helper.ResponseComplete += new VESHTER.HttpResponseCompleteEventHandler(this.CommandComplete);
                    //helper.Execute();

                    //foreach (System.IO.FileInfo info in dlg.Files)
                    //{
                    //    post.Post();
                    //}

                }
            }
        }
开发者ID:veshter,项目名称:tool,代码行数:30,代码来源:Page.xaml.cs

示例5: BtnBrowseImage_Click

 private void BtnBrowseImage_Click(object sender, RoutedEventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog
     {
         Multiselect = false, //Filter = "Jpeg Files (*.jpg)|*.jpg|All Files(*.*)|*.*",
         Filter = "JPEG Images (*.jpeg *.jpg)|*.jpeg;*.jpg|Png Images (*.png)|*.png",
     };
     if (ofd.ShowDialog() == true)
     {
         try
         {
             LoadingInfo.Visibility = System.Windows.Visibility.Visible;
             focusRectangle.Viewport.Visibility = System.Windows.Visibility.Collapsed;
             focusRectangle.LoadImageStream(ofd.File.OpenRead(), ZoomInOut);
             fileInfo = ofd.File;
             BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = false;
             ZoomInOut.IsEnabled = true;
             System.Threading.Timer timer = new System.Threading.Timer(TimerCallback,
                  new LoadingState()
                  {
                      focusRectangle = focusRectangle,
                      LoadingInfo = LoadingInfo,
                      BtnUploadImage = BtnUploadImage,
                      BtnAdvanceMode = BtnAdvanceMode
                  } as object,
                  1000, 500);   
         }
         catch (Exception exception)
         {
             Utils.ShowMessageBox("文件无效:" + exception.Message);
             ZoomInOut.IsEnabled = false;
             BtnUploadImage.IsEnabled = BtnAdvanceMode.IsEnabled = false;
         }
     }
 }
开发者ID:wenysky,项目名称:dnt31-lite,代码行数:35,代码来源:ImageBrowser.xaml.cs

示例6: btnFile2_Click

        private void btnFile2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var dialog = new OpenFileDialog { Multiselect = false };
                if (dialog.ShowDialog() == true)
                {
                    using (var stream = dialog.File.OpenRead())
                    {
                        StreamReader sr = new StreamReader(stream, new Gb2312Encoding());
                        strDst = sr.ReadToEnd();

                        // 删除多余的换行
                        strDst = strDst.Replace("\0", "");

                        if (!string.IsNullOrEmpty(strDst))
                            CompareFile();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:kuki89,项目名称:IP_Lab,代码行数:25,代码来源:WndFileCompare.xaml.cs

示例7: SilverlightLoadModelDialog

 public SilverlightLoadModelDialog()
 {
     _loadFileDialog = new OpenFileDialog
     {
         Filter = "Turtle Pictures (.tur)|*.tur",
     };
 }
开发者ID:dunnmike602,项目名称:Silver-Turtle,代码行数:7,代码来源:SilverlightLoadModelDialog.cs

示例8: View_SetFocus

 private void View_SetFocus(object sender, EventArgs e)
 {
     try
     {
         if (sender is int)
         {
             switch (Convert.ToInt32(sender))
             {
                 case 0:
                     OpenFileDialog op = new OpenFileDialog();
                     op.Filter = "Excel xml (*.xml)|*.xml";
                     if (op.ShowDialog() == true)
                     {
                         if (this.DataContext is UploadSubjectViewModel)
                         {
                             (this.DataContext as UploadSubjectViewModel).OnGetFileClickComplete(op.File);
                         }
                     }
                     break;
             }
         }
         if (sender is List<CustomizeSubjectType>)
         {
             Telerik.Windows.Controls.GridViewComboBoxColumn col = rgvData.Columns["type"] as Telerik.Windows.Controls.GridViewComboBoxColumn;
             if (col != null)
             {
                 col.ItemsSource = sender as List<CustomizeSubjectType>;
             }
         }
     }
     catch (Exception ex)
     {
         MessageCustomize.Show(ex.Message);
     }
 }
开发者ID:hieu292,项目名称:hrm-k14vlu,代码行数:35,代码来源:UploadSubjectView.xaml.cs

示例9: Browse

        private async void Browse()
        {
            var dlg = new OpenFileDialog
            {
                Multiselect = false,
                Filter = "JPEG Images (*.jpg, *.jpeg)|*.jpg;*.jpeg"
            };

            if (dlg.ShowDialog() == true)
            {
                var file = dlg.File;

                var progress = new ProgressWindow { Content = "Закачиваем файл..." };
                progress.Show();

                var task = await filesRepository.Create(file.OpenRead(), file.Name, "image/jpeg");

                if (task.Succeed)
                {
                    var fileId = task.Result;
                    var task2 = await productsRepository.AttachFile(productId, fileId);
                    if (task2.Succeed)
                    {
                        await LoadFiles();
                    }
                }

                progress.Close();
            }
        }
开发者ID:hva,项目名称:warehouse.net,代码行数:30,代码来源:AttachmentsViewModel.cs

示例10: btnOpenLog_Click

        private void btnOpenLog_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Log Files (.log)|*.log|All Files (*.*)|*.*";
            dlg.FilterIndex = 1;

            bool? userClickedOK = dlg.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK == true)
            {
                grdLog.ItemsSource = null;
                // Open the selected file to read.
                System.IO.Stream fileStream = dlg.File.OpenRead();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
                {
                    try
                    {
                        Log.Instance.InitializeFromStream(reader);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("There was an error reading this log file. { " + ex.StackTrace + " }");
                    }
                }
                fileStream.Close();
                grdLog.ItemsSource = Log.Instance.Items;
            }
        }
开发者ID:garethconner,项目名称:SpikeMarkLogViewer,代码行数:29,代码来源:MainPage.xaml.cs

示例11: SelectFilesButton_Click

        /// <summary>
        ///     选择文件对话框事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectFilesButton_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog {Multiselect = true};

            try
            {
                if (!string.IsNullOrEmpty(_fileFilter))
                    ofd.Filter = _fileFilter;
            }
            catch (ArgumentException ex)
            {
                //User supplied a wrong configuration file
                throw new Exception("Wrong file filter configuration.", ex);
            }

            if (ofd.ShowDialog() != true) return;
            foreach (var file in ofd.Files)
            {
                var userFile = new UploadFile
                {
                    FileName = file.Name,
                    FileStream = file.OpenRead()
                };

                if (userFile.FileStream.Length <= _maxFileSize)
                {
                    //向文件列表中添加文件信息
                    _files.Add(userFile);
                }
                else
                {
                    MessageBox.Show( "Maximum file size is: " + (_maxFileSize/1024) + "KB.");
                }
            }
        }
开发者ID:raulalf7,项目名称:ALF_TOOLS,代码行数:40,代码来源:MainPage.xaml.cs

示例12: BrowseButton_Click

        /// <summary>

        /// Browse button

        /// </summary>

        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {

            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Limit the dialog to only show ".csv" files,

            // modify this as necessary to allow other file types

            openFileDialog.Filter = "xml (*.xml)|*.xml";

            openFileDialog.FilterIndex = 1;

            openFileDialog.Multiselect = true;
            documentStream = new List<FileStream>();
            if (openFileDialog.ShowDialog() == true)
            {

                foreach (FileInfo file in openFileDialog.Files)
                {
                    this.FileTextBox.Text += file.Name + ",";

                    System.IO.FileStream myStream = file.OpenRead();

                    documentStream.Add(myStream);
                }
                this.FileTextBox.IsReadOnly = true;

            }

        }
开发者ID:natovichat,项目名称:binyamin,代码行数:37,代码来源:Copy+of+SelectFileWindow.cs

示例13: PromptForParts

        public void PromptForParts(Action<IEnumerable<ComposablePartCatalog>> callback)
        {
            if (callback != null)
            {
                List<ComposablePartCatalog> catalogs = new List<ComposablePartCatalog>();

                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "XAPs (*.xap)|*.xap";
                dialog.Multiselect = false;

                if (dialog.ShowDialog() == true)
                {
                    var fileStream = dialog.File.OpenRead();

                    var assemblies = Package.LoadPackagedAssemblies(fileStream);

                    AggregateCatalog catalog = new AggregateCatalog();

                    CatalogHelper.DiscoverParts(catalog, assemblies);

                    catalogs.Add(catalog);
                }

                callback(catalogs);
            }
        }
开发者ID:nblumhardt,项目名称:MefContrib-Tools,代码行数:26,代码来源:PartService.Silverlight.cs

示例14: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "JPEG / PNG (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png";
            if (openDialog.ShowDialog().GetValueOrDefault(false))
            {
                using (FileStream stream = openDialog.File.OpenRead())
                {
                    wb = ImageHelper.GetImageSource(stream, 700, 700);
                }

                //byte[] buffer;
                //using (
                    Stream Source = JpgEncoder.Encode(wb, 85); //)
                {
                    //int bufferSize = Convert.ToInt32(Source.Length);
                    //buffer = new byte[bufferSize];
                    //Source.Read(buffer, 0, bufferSize);

                    //Create a new UserFile object

                    _file.FileName = openDialog.File.Name;
                    _file.FileStream = Source;
                    //userFile.UIDispatcher = this.Dispatcher;
                    _file.UploadContainerUrl = _uploadContainerUrl;

                    _file.Upload(null);

                    //Source.Close();
                }
            }
        }
开发者ID:jkresner,项目名称:Climbfind_v4_2011,代码行数:32,代码来源:MainPage.xaml.cs

示例15: Open

        public IEnumerable<IResult> Open()
        {
            var dialog = new OpenFileDialog();
            yield return Show.OpenFileDialog(dialog);

            yield return Show.MessageBox("You opened " + dialog.File.Name + ".", "File");
        }
开发者ID:ssethi,项目名称:TestFrameworks,代码行数:7,代码来源:BazViewModel.cs


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