當前位置: 首頁>>代碼示例>>C#>>正文


C# SaveFileDialog.OpenFile方法代碼示例

本文整理匯總了C#中System.Windows.Forms.SaveFileDialog.OpenFile方法的典型用法代碼示例。如果您正苦於以下問題:C# SaveFileDialog.OpenFile方法的具體用法?C# SaveFileDialog.OpenFile怎麽用?C# SaveFileDialog.OpenFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.SaveFileDialog的用法示例。


在下文中一共展示了SaveFileDialog.OpenFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExportToTxt

 public void ExportToTxt(DataView dv)
 {
     string fn = "bf" + Common.ChineseToSpell.GetChineseSpell(cmbLb.SelectedValue.ToString()).ToLower();//此處把值轉換為拚音
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
     saveFileDialog1.Filter = "txt(*.txt)|*.txt";
     saveFileDialog1.FilterIndex = 0;
     saveFileDialog1.RestoreDirectory = true;
     saveFileDialog1.CreatePrompt = true;
     saveFileDialog1.Title = "導出txt文件到 ";
     DateTime now = DateTime.Now;
     saveFileDialog1.FileName = fn;
     saveFileDialog1.ShowDialog();
     Stream myStream;
     myStream = saveFileDialog1.OpenFile();
     StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
     for (int rowNo = 0; rowNo < dv.Count; rowNo++)
     {
         String tempstr = "";
         for (int columnNo = 0; columnNo < dv.Table.Columns.Count; columnNo++)
         {
             if (columnNo > 0)
             {
                 tempstr += "\t ";
             }
             tempstr += dv.Table.Rows[rowNo][columnNo].ToString();
         }
         sw.WriteLine(tempstr);
     }
     sw.Close();
     myStream.Close();
 }
開發者ID:SoMeTech,項目名稱:hnbthelper,代碼行數:31,代碼來源:frmBFimp.cs

示例2: btn_FileSave_Click

        private void btn_FileSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Title = "파일 저장 대화상자 예제";
            dlg.CreatePrompt = true;
            dlg.OverwritePrompt = true;
            dlg.FileName = "default";
            dlg.DefaultExt = "rtf";
            dlg.InitialDirectory = "c:\\";
            dlg.Filter = "RichText files (*.rtf)|*.rtf";

            System.IO.MemoryStream memstream = new System.IO.MemoryStream();
            this.richTextBox1.SaveFile(memstream, RichTextBoxStreamType.RichText);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    System.IO.Stream fs = dlg.OpenFile();
                    memstream.Position = 0;
                    memstream.WriteTo(fs);
                    fs.Close();
                    this.textBox1.Text = dlg.FileName + " [[파일저장]]";
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
開發者ID:gawallsibya,項目名稱:BIT_MFC-CShap-DotNet,代碼行數:31,代碼來源:Form1.cs

示例3: cSVToolStripMenuItem_Click

        private void cSVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.FileName = "workhistory.csv";
            sfd.InitialDirectory = @"C:\";
            sfd.Title = "保存先のファイルを選択してください";
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                System.IO.Stream stream;
                stream = sfd.OpenFile();
                if (stream != null)
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(stream, new UTF8Encoding(true));

                    //header
                    sw.WriteLine("name, date, starttime, endtime, duration");

                    List<JobRecord> records = jobManager.GetAllJobRecords();
                    foreach (JobRecord record in records)
                    {
                        sw.WriteLine("{0},{1},{2},{3},{4}", record.name, record.date, record.startTime, record.endTime, record.duration);
                    }

                    sw.Close();
                    stream.Close();
                }
            }
        }
開發者ID:ebibibi,項目名稱:TimeLog,代碼行數:29,代碼來源:MainForm.cs

示例4: SaveToFile

 internal void SaveToFile()
 {
     SaveFileDialog sfd = new SaveFileDialog();
     sfd.AddExtension = true;
     //sfd.CheckFileExists = true;
     //sfd.CheckPathExists = true;
     sfd.CreatePrompt = true;
     sfd.DefaultExt = "rtf";
     sfd.Filter = "リッチテキストフォーマット|*.rtf";
     if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
     {
         Stream write = null;
         try
         {
             write = sfd.OpenFile();
             rtb_thread_main.SaveFile(write, RichTextBoxStreamType.RichText);
             MessageBox.Show("セーブ成功しました。");
         }
         catch (System.IO.IOException)
         {
             MessageBox.Show("セーブ失敗ました。");
         }
         finally
         {
             if (write != null)
             {
                 write.Close();
             }
         }
     }
 }
開發者ID:MaiReo,項目名稱:SimpleRobotDemo,代碼行數:31,代碼來源:frm_NewThread.cs

示例5: button_fileExport_Click

        private void button_fileExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog ();
            saveFileDialog.Filter = "CSV file|*.csv";
            saveFileDialog.Title = "Export current view to CSV";
            saveFileDialog.ShowDialog ();

            if (saveFileDialog.FileName != string.Empty)
            {
                FileStream fs = (FileStream)saveFileDialog.OpenFile ();

                try
                {
                    CSVExporter.ExportCSV (dataManager.GetData (), fs);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine (ex.StackTrace);
                }
                finally
                {
                    fs.Close ();
                }
            }
        }
開發者ID:sandormatyi,項目名稱:AVMS,代碼行數:25,代碼來源:MainForm.cs

示例6: save

        public void save()
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "WLD files (*.wld)|*.wld|All files (*.*)|*.*";
            dialog.FileName = "S7PROG.wld";
            dialog.FilterIndex = 1;
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                System.IO.Stream fs;
                if ((fs = dialog.OpenFile()) != null)
                {
                    try
                    {
                        fs.Write(this.data.ToArray(), 0, this.data.Count);
                    }
                    catch
                    {
                        MessageBox.Show("Error saving file");
                    }
                    finally
                    {
                        fs.Close();
                    }
                }
            }

        }
開發者ID:kukubadze,項目名稱:Tungsten,代碼行數:29,代碼來源:wldFile.cs

示例7: CommonExport

        public void CommonExport()
        {
            DialogResult result = new DialogResult();
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.RestoreDirectory = false;
            dialog.Filter = "PNG Image (*.png) [Recommended]|*.png|JPEG Image (*.jpeg) [Bad Idea]|*.jpg|BMP Image (*.bmp)|*.bmp";
            dialog.FileName = Path.ChangeExtension(filename, null);
            dialog.AddExtension = true;
            result = dialog.ShowDialog();
            if (dialog.FileName != "" && result == DialogResult.OK)
            {
                System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile();
                switch (dialog.FilterIndex)
                {
                    case 1:
                        bitmap.Save(fs,
                        System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    case 2:
                        bitmap.Save(fs,
                        System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 3:
                        bitmap.Save(fs,
                        System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                }
                fs.Close();
            }
        }
開發者ID:Dahrkael,項目名稱:RMDSCM,代碼行數:32,代碼來源:Image.cs

示例8: button2_Click

      private void button2_Click(object sender, EventArgs e)
      {
          SaveFileDialog sfd = new SaveFileDialog();
          sfd.Filter = "JPeg Imagen|*.jpg|Bitmap Imagen|*.bmp|PNG Imagen|*.png";
          sfd.Title = "Guardar grafico en imagen";
          sfd.ShowDialog();
          if(sfd.FileName != "")
          {
              FileStream fs = (FileStream)sfd.OpenFile();
              switch (sfd.FilterIndex)
              {
                  case 1:
                      this.chart1.SaveImage(fs, ChartImageFormat.Jpeg);
                      break;
                  case 2:
                      this.chart1.SaveImage(fs, ChartImageFormat.Bmp);
                      break;
                  case 3:
                      this.chart1.SaveImage(fs, ChartImageFormat.Png);
                      break;
 
              }
              fs.Close();
          }
      }
開發者ID:santii810,項目名稱:Dam209,代碼行數:25,代碼來源:Form1.cs

示例9: saveGraphToFile

        public bool saveGraphToFile(GraphClass graph)
        {
            // saving to user named file and user selected dir

            Stream TestFileStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Graph file (*.gph)|*.gph";
            saveFileDialog1.FilterIndex = 1;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((TestFileStream = saveFileDialog1.OpenFile()) != null)
                {
                    BinaryFormatter serializer = new BinaryFormatter();
                    serializer.Serialize(TestFileStream, graph);
                    TestFileStream.Close();
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
開發者ID:Wackalooon,項目名稱:GraphDesigner,代碼行數:26,代碼來源:SerializeHandlerClass.cs

示例10: BtnSave_Click

        private void BtnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Bitmap Image|*.bmp|JPEG Image|*.jpg";
            dialog.Title = "Save Image";
            dialog.ShowDialog();

            if (dialog.FileName != "")
            {
                System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile();

                switch (dialog.FilterIndex)
                {
                    case 1:
                        PBOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;

                    case 2:
                        PBOutput.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;
                }

                fs.Close();
            }
        }
開發者ID:Hawriluk,項目名稱:Hawriluk_coursWork,代碼行數:25,代碼來源:Form1.cs

示例11: buttonL_Click

        private void buttonL_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog
            {
                Title = "保存L矩陣結果",
                CheckPathExists = true,
                InitialDirectory = @"E:\大學\大三下\攝影測量學\攝影測量學作業\Data",
                Filter = "txt文件(*.txt)|*.txt"
            };
            if (sfd.ShowDialog() != DialogResult.OK) return;
            using (StreamWriter sw = new StreamWriter(sfd.OpenFile(), Encoding.Default))
            {
                StringBuilder sb = new StringBuilder();
                var data = _ro.FirstL.Data;

                for (int i = 0; i < data.GetLength(0); i++)
                {
                    for (int j = 0; j < data.GetLength(1); j++)
                    {
                        sb.Append(data[i, j] + "\t");
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.AppendLine();
                }

                sw.Write(sb.ToString());
            }
        }
開發者ID:CptTZ,項目名稱:Photogrammetry-Assignment-2,代碼行數:28,代碼來源:ViewData.cs

示例12: saveCollection_Click

        private void saveCollection_Click(object sender, EventArgs e)
        {
            if (Interval.Text == "") { Interval.Text = "1"; }
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = " | *.pix";
            saveDialog.DefaultExt = "pix";

            if (FileList.Items.Count == 0)
            {
                MessageBox.Show("No file names to save.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            if (openCollectionFileName == null)
                saveDialog.FileName = null;
            else
                saveDialog.FileName = openCollectionFileName;

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                StreamWriter streamWriter = new StreamWriter(saveDialog.OpenFile());
                foreach (string item in FileList.Items)
                {
                    streamWriter.WriteLine(item);
                }
                streamWriter.Close();
            }
        }
開發者ID:zganger,項目名稱:SlideViewer,代碼行數:28,代碼來源:SlideViewer.cs

示例13: myComputerToolStripMenuItem_Click

        private void myComputerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            SaveFileDialog theDialog = new SaveFileDialog();
            theDialog.Title = "Save Text File";
            theDialog.Filter = "text files|*.txt";
            theDialog.InitialDirectory = @"C:\";
            if (theDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = theDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.

                            richTextBox1.SaveFile(myStream, RichTextBoxStreamType.PlainText);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
開發者ID:donxnik,項目名稱:MadHackers-DoNxNick,代碼行數:27,代碼來源:Form1.cs

示例14: Main

        static void Main(string[] args)
        {
            ConsoleColor old = Console.ForegroundColor;
            try{
                var props = new ConnectionProperties();
                using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom))
                {
                    var result = frm.ShowDialog();
                    if (result != System.Windows.Forms.DialogResult.OK)
                        return;
                }

                var cxi = new FakeConnection();
                new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props);

                var driver = new MongoDynamicDataContextDriver();

                List<Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList();
                var code = driver.GetStaticCodeFiles()
                    .Concat(new string[] {driver.GenerateDynamicCode(props, assemblies, "", "driver")});
                if(props.InitializationQuery != null)
                    code = code.Concat(new string[]{driver.GenerateCustomInitQuery(props.InitializationQuery, "driver")});

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("------------------------------------------------");
                foreach (string s in code)
                {
                    Console.WriteLine(s);
                    Console.WriteLine("------------------------------------------------");
                }
                Console.ForegroundColor = old;

                using (var frm = new SaveFileDialog())
                {
                    var result = frm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
                        {
                            foreach (string s in code)
                            {
                                writer.WriteLine(s);
                                writer.WriteLine("---------------------------------------------------");
                            }

                            writer.Flush();
                        }

                    }
                }

            }catch(Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
            }
            finally{
                Console.ForegroundColor = old;
            }
        }
開發者ID:gburgett,項目名稱:LinqPad-mongo-driver,代碼行數:60,代碼來源:Program.cs

示例15: createFileToolStripMenuItem_Click

        /// <summary>
        /// Opens a file dialog that allows for creation of multiple databases
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createFileToolStripMenuItem_Click (object sender, EventArgs e) {
            Stream newFileStream;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "SQLite files (*.sqlite)|*.sqlite";
            saveFileDialog.FilterIndex = 2;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK) {
                if ((newFileStream = saveFileDialog.OpenFile()) != null) {
                    
                    if (File.Exists(saveFileDialog.FileName)) {
                        newFileStream.Close();

                        DB = new SQLite.SQLiteConnection(saveFileDialog.FileName);
                        DB_Connection = saveFileDialog.FileName;

                        // Hard coded members class, need to add custom table structure
                        DB.CreateTable<Members>();

                        // Possibly save DB
                        SetView();
                    }
                    
                }
            }


        }
開發者ID:FissionTech,項目名稱:PBL-HR,代碼行數:34,代碼來源:Main.cs


注:本文中的System.Windows.Forms.SaveFileDialog.OpenFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。