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


C# System.Windows.Forms.OpenFileDialog.OpenFile方法代码示例

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


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

示例1: OnClickFindBtn2

        private void OnClickFindBtn2(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                textBox2.Text = ofd.SafeFileName;

                try
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(ofd.OpenFile());
                    string content = sr.ReadToEnd();
                    sr.Close();

                    selectTextBeforeValue.Text = content;
                    content = System.Text.RegularExpressions.Regex.Replace(content, "a", "QQQ");

                    System.IO.StreamWriter writer = new System.IO.StreamWriter(ofd.FileName);
                    writer.Write(content);
                    writer.Close();

                    sr = new System.IO.StreamReader(ofd.OpenFile());
                    content = sr.ReadToEnd();
                    sr.Close();

                    selectTextAfterValue.Text = content;
                }
                catch(Exception ex)
                {
                    Console.WriteLine("=-=-=-=Exception : " + ex);
                }
            }
        }
开发者ID:hrSung,项目名称:ModernUITestProject,代码行数:34,代码来源:Home.xaml.cs

示例2: OpenMenuItem_Click

 private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
     dialog.DefaultExt = ".bvh";
     dialog.Filter = "BVHファイル(*.bvh)|*.bvh";
     if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         BVH bvh = new BVH();
         bvh.Load(dialog.OpenFile());
         bvhFrom.BVH = bvh;
         bvhTo.BVH = bvh.Convert();
         menuItemUseAll.IsChecked = false;
     }
 }
开发者ID:sinnosuke,项目名称:MMDBVHToSLBVH,代码行数:14,代码来源:Window1.xaml.cs

示例3: LoadMap

        public void LoadMap()
        {
            /* Temporaily ask the player for a maze to load if maze doesn't exist */

            // Create a stream for loading the file
            Stream loadStream;

            // Create a dialog for asking for save location
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
            dialog.Filter = "maze files (*.maz)|*.maz";
            dialog.InitialDirectory = Directory.GetCurrentDirectory() + "\\DefaultMazes\\";

            // Ask the user for a file to load
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && (loadStream = dialog.OpenFile()) != null)
            {
                maze = new Maze(loadStream, GraphicsDevice.Viewport);
                stateGame = GameState.Play;
            }
        }
开发者ID:svaswani,项目名称:MinotaurEscape,代码行数:19,代码来源:Game1.cs

示例4: ParseSCPD

        internal void ParseSCPD(String XML, int startLine)
        {
            bool loadSchema = false;
            string schemaUrn = "";

            if (XML == "")
            {
                return;
            }

            string evented = "no";
            string multicast = "no";
            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "scpd")
            {
                try
                {
                    if (XMLDoc.HasAttributes)
                    {
                        // May be UPnP/1.1 SCPD
                        for (int i = 0; i < XMLDoc.AttributeCount; i++)
                        {
                            XMLDoc.MoveToAttribute(i);
                            if (XMLDoc.Prefix == "xmlns")
                            {
                                loadSchema = true;
                                schemaUrn = XMLDoc.Value;
                            }
                            // ToDo: Try to load the schema from the network first
                            //						if (XMLDoc.LocalName=="schemaLocation")
                            //						{
                            //							if (XMLDoc.Value=="http://www.vendor.org/Schemas/Sample.xsd")
                            //							{
                            //								schemaUrn = XMLDoc.LookupNamespace(XMLDoc.Prefix);
                            //							}
                            //						}
                        }
                        XMLDoc.MoveToElement();

                        if (loadSchema)
                        {
                            // Prompt Application for local Schema Location
                            System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog();
                            fd.Multiselect = false;
                            fd.Title = schemaUrn;
                            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                FileStream fs = (FileStream)fd.OpenFile();
                                System.Text.UTF8Encoding U = new System.Text.UTF8Encoding();
                                byte[] buffer = new byte[(int)fs.Length];
                                fs.Read(buffer, 0, buffer.Length);
                                UPnPComplexType[] complexTypes = UPnPComplexType.Parse(U.GetString(buffer));
                                fs.Close();
                                foreach (UPnPComplexType complexType in complexTypes)
                                {
                                    this.AddComplexType(complexType);
                                }
                            }
                        }
                    }


                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                    while ((XMLDoc.LocalName != "scpd") && (XMLDoc.EOF == false))
                    {
                        if (XMLDoc.LocalName == "actionList" && !XMLDoc.IsEmptyElement)
                        {
                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while ((XMLDoc.LocalName != "actionList") && (XMLDoc.EOF == false))
                            {
                                if (XMLDoc.LocalName == "action")
                                {
                                    int embeddedLine = XMLDoc.LineNumber;
                                    //ParseActionXml("<action>\r\n" + XMLDoc.ReadInnerXml() + "</action>", embeddedLine);
                                    ParseActionXml(XMLDoc.ReadOuterXml(), embeddedLine-1);
                                }
                                if (!XMLDoc.IsStartElement())
                                {
                                    if (XMLDoc.LocalName != "actionList")
                                    {
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (XMLDoc.LocalName == "serviceStateTable")
                            {
                                XMLDoc.Read();
                                XMLDoc.MoveToContent();

//.........这里部分代码省略.........
开发者ID:Scannow,项目名称:SWYH,代码行数:101,代码来源:UPnPService.cs

示例5: ParseSCPD

        /// <summary>
        /// Parses a service xml into the UPnPservice instance. The instance will have been created by
        /// parsing the Service element from the Device xml, see <see cref="UPnPService.Parse">Parse method</see>
        /// </summary>
        /// <param name="XML">the xml containing the service description</param>
        internal void ParseSCPD(String XML)
        {
            bool loadSchema = false;
            string schemaUrn = "";
            if (XML == "")
            {
                return;
            }

            string evented = "no";
            string multicast = "no";
            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "scpd")
            {
                if (XMLDoc.HasAttributes)
                {
                    // May be UPnP/1.1 SCPD
                    for (int i = 0; i < XMLDoc.AttributeCount; i++)
                    {
                        XMLDoc.MoveToAttribute(i);
                        if (XMLDoc.Prefix == "xmlns")
                        {
                            loadSchema = true;
                            schemaUrn = XMLDoc.Value;
                        }
                        // ToDo: Try to load the schema from the network first
                        //						if (XMLDoc.LocalName=="schemaLocation")
                        //						{
                        //							if (XMLDoc.Value=="http://www.vendor.org/Schemas/Sample.xsd")
                        //							{
                        //								schemaUrn = XMLDoc.LookupNamespace(XMLDoc.Prefix);
                        //							}
                        //						}
                    }
                    XMLDoc.MoveToElement();

                    if (loadSchema)
                    {
                        // Prompt Application for local Schema Location
                        System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog();
                        fd.Multiselect = false;
                        fd.Title = schemaUrn;
                        if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            FileStream fs = (FileStream)fd.OpenFile();
                            System.Text.UTF8Encoding U = new System.Text.UTF8Encoding();
                            byte[] buffer = new byte[(int)fs.Length];
                            fs.Read(buffer, 0, buffer.Length);
                            UPnPComplexType[] complexTypes = UPnPComplexType.Parse(U.GetString(buffer));
                            fs.Close();
                            foreach (UPnPComplexType complexType in complexTypes)
                            {
                                this.AddComplexType(complexType);
                            }
                        }
                    }
                }

                XMLDoc.Read();
                XMLDoc.MoveToContent();
                while ((XMLDoc.LocalName != "scpd") && (XMLDoc.EOF == false))
                {
                    if (XMLDoc.LocalName == "actionList" && !XMLDoc.IsEmptyElement)
                    {
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                        while ((XMLDoc.LocalName != "actionList") && (XMLDoc.EOF == false))
                        {
                            if (XMLDoc.LocalName == "action")
                            {
                                string actionxml = "Failed to read the Action element from the source xml.";
                                try
                                {
                                    //TODO: DONE Resilience case 4 & 2 - if action fails itself (or underlying arguments), don't add it.
                                    //Wrap in try-catch
                                    actionxml = "<action>\r\n" + XMLDoc.ReadInnerXml() + "</action>";
                                    ParseActionXml(actionxml);
                                }
                                catch (Exception e)
                                {
                                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "Invalid Action XML");
                                    OpenSource.Utilities.EventLogger.Log(e, "XML content: \r\n" + actionxml);
                                    OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Warning, "Dropping failed Action and commencing parsing remainder of device");
                                }
                            }
                            if (!XMLDoc.IsStartElement())
                            {
                                if (XMLDoc.LocalName != "actionList")
                                {
                                    XMLDoc.Read();
//.........这里部分代码省略.........
开发者ID:Tieske,项目名称:Developer-Tools-for-UPnP-Technologies,代码行数:101,代码来源:UPnPService.cs

示例6: loadPlayer

        public Player loadPlayer()
        {
            Player temp = null;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            Stream myStream;
            dlg.Filter = "He Dies At The End (.hdate) | *.hdate";

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK == true)
            {
                if ((myStream = dlg.OpenFile()) != null)
                {
                    IFormatter formatter = new BinaryFormatter();
                    temp = (Player)formatter.Deserialize(myStream);
                    myStream.Close();
                }
            }
            return temp;
        }
开发者ID:Josh-Russell,项目名称:HDATE,代码行数:19,代码来源:MainWindow.xaml.cs

示例7: LoadMap

        public void LoadMap()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            openFileDialog1.Filter = "RPG Map Files (.rpgmf)|*.rpgmf";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            System.Windows.Forms.DialogResult userClickedOK = openFileDialog1.ShowDialog();

            if (userClickedOK == System.Windows.Forms.DialogResult.OK)
            {
                // Open the selected file to read.
                System.IO.Stream fileStream = openFileDialog1.OpenFile();

                using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
                {
                    // Read the first line from the file and write it the textbox.
                    map.LoadMap(reader, openFileDialog1.FileName, toolmap);
                }
                fileStream.Close();
            }
        }
开发者ID:mikecrawford9,项目名称:cs134rpg,代码行数:22,代码来源:Game1.cs

示例8: RestoreAllDataClick

        private void RestoreAllDataClick(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

            openFileDialog1.InitialDirectory = Path.GetTempPath();
            openFileDialog1.Filter = "archive files (*.zip)|*.7z|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (ZipArchive archive = new ZipArchive(openFileDialog1.OpenFile()))
                {
                    // TODO: What does restore mean? Right now, just extracts to temp.
                    // would have to do some somersaults to switch DB and change app context to stored config.
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        entry.ExtractToFile(Path.Combine(Path.GetTempPath(), entry.FullName),true);
                    }
                }
            }
        }
开发者ID:hnordquist,项目名称:INCC6,代码行数:22,代码来源:MainWindow.xaml.cs

示例9: ShowFileDialog

        private void ShowFileDialog(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
                Multiselect = false,
                Title = "Select SMS ROM",
            };

            ofd.InitialDirectory = Environment.CurrentDirectory + "\\Test ROMs";
            ofd.ShowDialog();

            if (ofd.FileName.Length > 0)
            {
                System.IO.BinaryReader br = new System.IO.BinaryReader(ofd.OpenFile());
                byte[] data = br.ReadBytes((int)ofd.OpenFile().Length);

                StopCPU();

                Memory.Load(data);
            }
        }
开发者ID:BGCX262,项目名称:zsmse-svn-to-git,代码行数:23,代码来源:MainWindow.xaml.cs

示例10: ImportProxysExec

        private void ImportProxysExec()
        {
            Stream myStream = null;
            System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

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

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            StreamReader reader = new StreamReader(myStream);
                            string line;
                            //option.Proxys.Clear();
                            while ((line = reader.ReadLine()) != null)
                            {
                                option.Proxys.Add(new ProxyServer(line, true));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
开发者ID:caicaicai,项目名称:webTest,代码行数:34,代码来源:OptionViewModel.cs

示例11: ImportClick

        private void ImportClick(object sender, RoutedEventArgs e)
        {
            importFileDialog = new System.Windows.Forms.OpenFileDialog();
            importFileDialog.Multiselect = false;
            importFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            importFileDialog.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
            importFileDialog.FilterIndex = 0;
            importFileDialog.RestoreDirectory = false;

            if (importFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                XmlDocument tmpXml = new XmlDocument();
                tmpXml.Load(importFileDialog.OpenFile());

                XmlNodeList tmpCards = tmpXml.SelectNodes(@"//card");
                XmlNodeList tmpTranslations;
                List<string> tmpTranslationsList;
                string tmpWord;
                string[] separatedTranslations;

                foreach (XmlNode tmpCard in tmpCards)
                {
                    tmpWord = tmpCard.SelectSingleNode(@"word").InnerText.ToLower().Trim();
                    tmpTranslations = tmpCard.SelectNodes(@"meanings/meaning/translations/word");
                    tmpTranslationsList = new List<string>();
                    foreach (XmlNode tmpTranslation in tmpTranslations)
                    {
                        separatedTranslations = tmpTranslation.InnerText.ToLower().Split(',');
                        foreach (string tmpTranslationWord in separatedTranslations) tmpTranslationsList.Add(tmpTranslationWord.Trim());
                    }

                    if (!cards.ContainsKey(tmpWord))
                    {
                        cards.Add(tmpWord, new Card()
                        {
                            Mode = CardMode.Untouched,
                            Word = tmpWord,
                            Translations = tmpTranslationsList,
                            Shown = 0,
                            Tested = 0
                        });
                        cardsForDataGrid.Add(cards[tmpWord].Data);
                    }
                    else
                    {
                        cardsForDataGrid.Remove(cards[tmpWord].Data);
                        cards[tmpWord].Translations = cards[tmpWord].Translations.Concat(tmpTranslationsList).Distinct().ToList();
                        cards[tmpWord].Mode = CardMode.Untouched;
                        cardsForDataGrid.Add(cards[tmpWord].Data);
                    }
                }

                CardGrid.ItemsSource = null;
                CardGrid.ItemsSource = cardsForDataGrid;
            }
        }
开发者ID:jeremejevs,项目名称:word-cards,代码行数:56,代码来源:ManagementWindow.xaml.cs

示例12: MainWindow

        public MainWindow()
        {
            Log.writeToLog("Starting DatasetReviewer " + Assembly.GetExecutingAssembly().GetName().Version.ToString());

            do
            {
                bool r;
                do
                {
                    System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
                    dlg.Title = "Open Header file to be displayed...";
                    dlg.DefaultExt = ".hdr"; // Default file extension
                    dlg.Filter = "HDR Files (.hdr)|*.hdr"; // Filter files by extension
                    bool result = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    if (!result) Environment.Exit(0);

                    directory = System.IO.Path.GetDirectoryName(dlg.FileName); //will use to find other files in dataset
                    headerFileName = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName);
                    try
                    {
                        head = (new HeaderFileReader(dlg.OpenFile())).read();
                    }
                    catch (Exception e)
                    {
                        r = false; //loop around again
                        ErrorWindow ew = new ErrorWindow();
                        ew.Message = "Error reading Header file: " + e.Message;
                        continue;
                    }
                    ED = head.Events;

                    try
                    {
                        bdf = new BDFEDFFileStream.BDFEDFFileReader(
                            new FileStream(System.IO.Path.Combine(directory, head.BDFFile),
                                FileMode.Open, FileAccess.Read));
                    }
                    catch (Exception e)
                    {
                        r = false; //loop around again
                        ErrorWindow ew = new ErrorWindow();
                        ew.Message = "Error reading BDF file header: " + e.Message;
                        ew.ShowDialog();
                        continue;
                    }
                    BDFLength = (double)bdf.NumberOfRecords * bdf.RecordDurationDouble;

                    Window1 w = new Window1(this);
                    r = (bool)w.ShowDialog();

                } while (r == false);

                Log.writeToLog("     on dataset " + headerFileName);

                if (includeANAs)
                {
                    foreach (EventDictionaryEntry ede in ED.Values) // add ANA channels that are referenced by extrinsic Events
                    {
                        if (ede.IsCovered && ede.IsExtrinsic)
                        {
                            int chan = bdf.ChannelNumberFromLabel(ede.channelName);
                            if (!channelList.Contains(chan)) //don't enter duplicate
                                channelList.Add(chan);
                        }
                    }
                }
            } while (channelList.Count == 0);

            InitializeComponent();

            //initialize the individual channel graphs
            foreach (int i in channelList)
            {
                ChannelGraph pg = new ChannelGraph(this, i);
                GraphCanvas.Children.Add(pg);
            }

            Title = headerFileName; //set window title
            BDFFileInfo.Content = bdf.ToString();
            HDRFileInfo.Content = head.ToString();
            Event.EventFactory.Instance(head.Events); // set up the factory
            EventFileReader efr = null;
            try
            {
                    efr = new EventFileReader(
                        new FileStream(System.IO.Path.Combine(directory, head.EventFile),
                            FileMode.Open, FileAccess.Read)); // open Event file
                bool z = false;
                foreach (Event.InputEvent ie in efr)// read in all Events into dictionary
                {
                    if (ie.IsNaked)
                        events.Add(ie);
                    else if (events.Count(e => e.GC == ie.GC) == 0) //quietly skip duplicates
                    {
                        if (!z) //use first found covered Event to synchronize clocks
                            z = bdf.setZeroTime(ie);
                        events.Add(ie);
                    }
                }
                efr.Close(); //now events is Dictionary of Events in the dataset; lookup by GC
//.........这里部分代码省略.........
开发者ID:DOPS-CCI,项目名称:CCI_project,代码行数:101,代码来源:MainWindow.xaml.cs

示例13: LoadScript_Click

 private void LoadScript_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
     dlg.AddExtension = true;
     dlg.DefaultExt = ".bql";
     dlg.Title = "Specify the script file...";
     dlg.ValidateNames = true;
     dlg.FileOk += delegate(object s, System.ComponentModel.CancelEventArgs eArg) {
         Stream file = null;
         try
         {
             file = dlg.OpenFile();
             var reader = new StreamReader(file);
             var script = reader.ReadToEnd();
             ScriptInput.Text = script;
         }
         catch (Exception)
         {
             System.Windows.MessageBox.Show("Loading script from file failed. Check if the file exist and is readable.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         finally
         {
             if (file != null)
                 file.Close();
         }
     };
     dlg.ShowDialog();
 }
开发者ID:bnaand,项目名称:xBim-Toolkit,代码行数:28,代码来源:ScriptingControl.xaml.cs

示例14: OnClick_LoadScript

 private void OnClick_LoadScript(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
     dlg.AddExtension = true;
     dlg.DefaultExt = ".bql";
     dlg.Title = "Specify the script file";
     dlg.Filter = "Building Query Language|*.bql";
     dlg.FilterIndex = 0;
     dlg.ValidateNames = true;
     dlg.FileOk += delegate(object s, System.ComponentModel.CancelEventArgs eArg)
     {
         Stream file = null;
         string dataFormat = "Text";
         try
         {
             file = dlg.OpenFile();
             TextRange txtRange = new TextRange(ScriptText.Document.ContentStart, ScriptText.Document.ContentEnd);
             if (txtRange.CanLoad(dataFormat))
             {
                 txtRange.Load(file, dataFormat);
             }
             this.Title = "BQL Console - " + System.IO.Path.GetFileName(dlg.FileName);
         }
         catch (Exception ex)
         {
             System.Windows.MessageBox.Show(string.Format("Loading script from file failed : {0}.", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         finally
         {
             if (file != null)
                 file.Close();
         }
     };
     dlg.ShowDialog();
     ScriptText.RefreshKeyColour();
     
 }
开发者ID:bnaand,项目名称:xBim-Toolkit,代码行数:37,代码来源:MainWindow.xaml.cs

示例15: addDocFileButton_Click

        private void addDocFileButton_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog fileBrowser = new System.Windows.Forms.OpenFileDialog();
            fileBrowser.Filter = "Documents (*.doc;*.docx)|*.doc;*.docx|All files (*.*)|*.*";

            if (fileBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream docStream = null;
                try
                {
                    if ((docStream = fileBrowser.OpenFile()) != null)
                    {
                        using (docStream) { } // don't use the stream
                    }
                }
                catch (SystemException ex)
                {
                    addDocLocationLabel.Content = "";
                    Logger.log(TraceEventType.Critical, 9, "File exception\r\n" + ex.GetType() + ":" + ex.Message + "\r\n" + ex.StackTrace);
                    statusLabel.Content = "Error: Could not read file. Original error: " + ex.Message;
                    return;
                }

                // check if have merge doc
                if (!checkWord())
                {
                    addDocLocationLabel.Content = "";
                    return;
                }
                statusLabel.Content = "Click Yes in word...";
                //ghetto to make the label update
                Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                            new Action(delegate { }));

                Word.Document doc = wordApp.Application.Documents.Open(fileBrowser.FileName, ReadOnly: true, Visible: false);
                //Console.WriteLine(doc.MailMerge.State);
                //Console.WriteLine(doc.MailMerge.DataSource.ConnectString);
                //Console.WriteLine(doc.MailMerge.DataSource.QueryString);
                if (doc.MailMerge.State == Word.WdMailMergeState.wdMainAndDataSource)
                {
                    addDocLocationLabel.Content = fileBrowser.FileName;
                    statusLabel.Content = "Ready.";
                    //Console.WriteLine("" + doc.MailMerge.DataSource.DataFields[1].Value + doc.MailMerge.DataSource.DataFields[2].Value +
                    //doc.MailMerge.DataSource.DataFields[3].Value);
                }
                else
                {
                    addDocLocationLabel.Content = "";
                    statusLabel.Content = "Selected document does not have merge data.";
                }
                ((Word._Document)doc).Close(SaveChanges: false);
                Marshal.FinalReleaseComObject(doc);
            }
            else
            {
                addDocLocationLabel.Content = "";
            }
        }
开发者ID:Clam-,项目名称:AttachmentMailer,代码行数:58,代码来源:MainWindow.xaml.cs


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