当前位置: 首页>>代码示例>>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;未经允许,请勿转载。