OpenFile() public method

public OpenFile ( ) : Stream
return Stream
Example #1
1
 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();
 }
        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);
                }
            }
        }
Example #3
0
        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();
                }
            }
        }
Example #4
0
 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();
             }
         }
     }
 }
Example #5
0
        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 ();
                }
            }
        }
Example #6
0
        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();
                    }
                }
            }

        }
Example #7
0
        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();
            }
        }
Example #8
0
      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();
          }
      }
        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;
        }
Example #10
0
        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();
            }
        }
        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());
            }
        }
Example #12
0
        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();
            }
        }
Example #13
0
        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);
                }
            }
        }
Example #14
0
        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;
            }
        }
Example #15
0
        /// <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();
                    }
                    
                }
            }


        }
Example #16
0
        private void btnBuyItems_Click(object sender, EventArgs e)
        {
            Stream myStream; //Declears a stream.
            PDFReceipt pdfWriter = new PDFReceipt(_userManager); // Creates a new instance of PDFReceipt class and sending the _usermanager refrence.
            SaveFileDialog saveFile = new SaveFileDialog(); // Creates a new SaveFileDialog.
            saveFile.FileName = "MyReceipt";        // Sets standard filename.
            saveFile.DefaultExt = ".pdf";          // Sets the default extension.
            saveFile.Filter = "(.pdf)|*.pdf";     // Sets the filters avaiable to the user.

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFile.OpenFile()) != null)
                {
                    try
                    {
                        pdfWriter.PrintReceipt(_userManager.GetPersonalTrolly(), myStream); //Tries to create a .pdf receipt and write it to the stream.
                    }
                    catch(Exception)
                    {
                        MessageBox.Show("Failed to print receipt");
                    }
                    finally
                    {
                        myStream.Close(); // Closes stream.
                    }
                }
            }

            _currentUser.PersonalTrolly.Clear(); // Clears the personal trolly.
            UpdateGUI(_currentUser); // Updates the GUI.
        }
Example #17
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.IO.Stream striimini;
            SaveFileDialog tallennaDialogi = new SaveFileDialog();

            tallennaDialogi.Filter = "tekstitiedosto(*.txt)|*.txt";
            tallennaDialogi.FilterIndex = 2;
            tallennaDialogi.RestoreDirectory = true;

            if (tallennaDialogi.ShowDialog() == DialogResult.OK)
            {
                if ((striimini = tallennaDialogi.OpenFile()) != null)
                {
                    string tallennettavat = puolueLaatikko1.Text + ":" + Environment.NewLine + "\t" + pelaajaNimiKentta1.Text + " ja " + pelaajaNimiKentta2.Text
                        + Environment.NewLine + puolueLaatikko2.Text + ":" + Environment.NewLine + "\t" + pelaajaNimiKentta3.Text + " ja " + pelaajaNimiKentta4.Text;
                    foreach (var element in jakoLista)
                    {
                        tallennettavat += Environment.NewLine + element.AnnaPisteet();
                    }
                    byte[] tallennus = System.Text.Encoding.UTF8.GetBytes(tallennettavat);
                    striimini.Write(tallennus, 0 , tallennus.Length);
                    striimini.Close();
                }
            }
        }
Example #18
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title = "Save an Image File";
            saveFileDialog1.ShowDialog();

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

                switch (saveFileDialog1.FilterIndex)
                {
                    case 1:
                        this.pictureBoxResultImage.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 2:
                        this.pictureBoxResultImage.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Bmp);
                        break;

                    case 3:
                        this.pictureBoxResultImage.Image.Save(fs,
                           System.Drawing.Imaging.ImageFormat.Gif);
                        break;
                }

                fs.Close();
            }
        }
        /// <summary>  
        /// 常用方法,列之间加\t,一行一行输出,此文件其实是csv文件,不过默认可以当成Excel打开。  
        /// </summary>  
        /// <remarks>  
        /// using System.IO;  
        /// </remarks>  
        /// <param name="dgv"></param>  
        public static void DataGridViewToExcel(DataGridView dgv)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Execl files (*.xls)|*.xls";
            dlg.FilterIndex = 0;
            dlg.RestoreDirectory = true;
            dlg.CreatePrompt = true;
            dlg.Title = "保存为Excel文件";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Stream myStream;
                myStream = dlg.OpenFile();
                StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0));
                string columnTitle = "";
                try
                {
                    //写入列标题
                    for (int i = 0; i < dgv.ColumnCount; i++)
                    {
                        if (i > 0)
                        {
                            columnTitle += "\t";
                        }
                        columnTitle += dgv.Columns[i].HeaderText;
                    }
                    sw.WriteLine(columnTitle);

                    //写入列内容
                    for (int j = 0; j < dgv.Rows.Count; j++)
                    {
                        string columnValue = "";
                        for (int k = 0; k < dgv.Columns.Count; k++)
                        {
                            if (k > 0)
                            {
                                columnValue += "\t";
                            }
                            if (dgv.Rows[j].Cells[k].Value == null)
                                columnValue += "";
                            else
                                columnValue += dgv.Rows[j].Cells[k].Value.ToString().Trim();
                        }
                        sw.WriteLine(columnValue);
                    }
                    sw.Close();
                    myStream.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
                finally
                {
                    sw.Close();
                    myStream.Close();
                }
            }
        }
Example #20
0
        //导出到Excel
        public static void exportDgvToExcel(DataGridView dgv)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Execl files (*.xls,*.xlsx)|*.xls";
            saveFileDlg.FilterIndex = 0;
            saveFileDlg.RestoreDirectory = true;
            saveFileDlg.CreatePrompt = true;
            saveFileDlg.Title = "Export Excel File To";
            if (saveFileDlg.ShowDialog() != DialogResult.OK)
                return;

            Stream myStream;
            myStream = saveFileDlg.OpenFile();
            //StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
            StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0));
            string str = "";
            try
            {
                //写标题
                for (int i = 0; i < dgv.ColumnCount; i++)
                {
                    if (!dgv.Columns[i].Visible) continue;
                    if (i > 0)
                    {
                        str += "\t";
                    }
                    str += dgv.Columns[i].HeaderText;
                }
                sw.WriteLine(str);
                //写内容
                for (int j = 0; j < dgv.Rows.Count; j++)
                {
                    string tempStr = "";
                    for (int k = 0; k < dgv.Columns.Count; k++)
                    {
                        if (!dgv.Columns[k].Visible) continue;
                        if (k > 0)
                        {
                            tempStr += "\t";
                        }
                        if (dgv.Rows[j].Cells[k].Value != null)
                            tempStr += dgv.Rows[j].Cells[k].Value.ToString();
                    }

                    sw.WriteLine(tempStr);
                }
                sw.Close();
                myStream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sw.Close();
                myStream.Close();
            }
        }
Example #21
0
        private void btnExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "����EXCE�ļ���";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream myStream;
                myStream = saveFileDialog.OpenFile();

                StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
                //StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0));
                string str = "";
                try
                {
                    //���
                    for (int i = 0; i < dgvMain.ColumnCount; i++)
                    {
                        if (i > 0)
                        {
                            str += "\t";
                        }
                        str += dgvMain.Columns[i].HeaderText;
                    }
                    sw.WriteLine(str);
                    //���
                    for (int j = 0; j < dgvMain.Rows.Count; j++)
                    {
                        string tempStr = "";
                        if (dgvMain.Rows[j].IsNewRow) continue;
                        for (int k = 0; k < dgvMain.Columns.Count; k++)
                        {
                            if (k > 0)
                            {
                                tempStr += "\t";
                            }
                            tempStr += dgvMain.Rows[j].Cells[k].Value.ToString();
                        }
                        sw.WriteLine(tempStr);
                    }
                    sw.Close();
                    myStream.Close();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                }
                finally
                {
                    sw.Close();
                    myStream.Close();
                }
            }
        }
Example #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "Png Image|*.png|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title = "Save an Image File";
            saveFileDialog1.ShowDialog();
            Random gen = new Random();
            SudokuTabla sud;

            Image img= new Bitmap(1020+20,520*(listBox1.SelectedIndex+1)/2);
            Graphics g = Graphics.FromImage(img);
                g.Clear(Color.White);
                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                g.TextContrast = 8;
            List<Image> lista = new List<Image>();
            for (int i = 0; i < listBox1.SelectedIndex + 1; i++) {
                 sud = new SudokuTabla(gen);
                sud.polni();
                sud.prazni();
                Image im= new Bitmap(500, 500);
                SimpleSudoku.draw(sud, im, Color.Black, true);
                g.DrawImageUnscaled(im, 500 * (i % 2)+20, 500 * (i / 2)+20);

            }

                // If the file name is not an empty string open it for saving.
                if (saveFileDialog1.FileName != "")
                {
                    // Saves the Image via a FileStream created by the OpenFile method.
                    System.IO.FileStream fs =
                       (System.IO.FileStream)saveFileDialog1.OpenFile();
                    // Saves the Image in the appropriate ImageFormat based upon the
                    // File type selected in the dialog box.
                    // NOTE that the FilterIndex property is one-based.
                    switch (saveFileDialog1.FilterIndex)
                    {
                        case 1:
                            img.Save(fs,
                             System.Drawing.Imaging.ImageFormat.Png);
                            break;

                        case 2:
                            img.Save(fs,
                               System.Drawing.Imaging.ImageFormat.Bmp);
                            break;

                        case 3:
                            img.Save(fs,
                               System.Drawing.Imaging.ImageFormat.Gif);
                            break;
                    }

                    fs.Close();
                }
        }
Example #23
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SaveFileDialog dialog = new SaveFileDialog();
     dialog.DefaultExt = "json";
     dialog.AddExtension = true;
     dialog.Filter = "Map Files (*.json)|*.json";
     dialog.FileOk += (zender, args) => OnSaveFileSelected(dialog.OpenFile());
     dialog.ShowDialog();
 }
        //export file
        private void button1_Click_1(object sender, EventArgs e)
        {
            int checkedTagNumber;
            Stream myStream;
            SaveFileDialog SaveFile = new SaveFileDialog();
            SaveFile.Title = "Save Text File";
            SaveFile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            SaveFile.FilterIndex = 2;

            if (SaveFile.ShowDialog() == DialogResult.OK)
            {
                if((myStream = SaveFile.OpenFile()) != null)
                {
                    userSelectedFilePath = SaveFile.FileName;
                    FilePath.Text = SaveFile.FileName;

                    myStream.Close();

                    if(ByLocation.Checked == true)
                    {
                        string city = swapString(City.Text);
                        string state = swapString(State.Text);
                        string country = swapString(Country.Text);

                        if(city == "" && state == "" && country == "")
                        {
                            MessageBox.Show("Location fields are empty!", "Error Message:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (DataValidation.validateCity(city) && DataValidation.validateState(state) && DataValidation.validateCountry(country))
                        {
                            BatchProcessing.ExportOnLocation(FilePath.Text, city, state, country, dm.getConnection());
                        }
                    }
                    else if(ByTagNumber.Checked == true)
                    {
                        if(TagNumber.Text == "")
                        {
                            MessageBox.Show("Tag number field is empty!", "Error Message:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if(!Int32.TryParse(TagNumber.Text, out checkedTagNumber))
                        {
                            MessageBox.Show("Tag number must be an integer!", "Error Message:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if(DataValidation.validateTagNumber(checkedTagNumber))
                        {
                            BatchProcessing.ExportOnTag(FilePath.Text, checkedTagNumber, dm.getConnection());
                        }
                    }
                    else
                    {
                        MessageBox.Show("Export method not selected!", "Error Message:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Example #25
0
        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog sFile = new SaveFileDialog();
            sFile.OpenFile();
            sFile.AddExtension = true;
            sFile.DefaultExt = ".xml";
            sFile.ShowDialog();

            NeuralNetwork.SaveNetworkToFile(charecterNet.GetNetworkData(), sFile.FileName);
            MessageBox.Show("Saved");
        }
Example #26
0
        //
        // define the writer class.  returns the number of tokens written.
        //
        public int CSVWrite(List<List<String>> data)
        {
            String fileName;
            int items = 0;

            // Displays a SaveFileDialog so the user can save the csv file
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "CSV File|*.csv|Polar File|*.pol|Text File|*.txt";
            saveFileDialog1.Title = "Save a CSV File";
            saveFileDialog1.ShowDialog();

            fileName = saveFileDialog1.FileName;

            // If the file name is not an empty string open it for saving.
            if (fileName == "")
            {
                return 0;
            }

            // Saves the Polar data via a FileStream created by the OpenFile method.
            FileStream fs = (FileStream)saveFileDialog1.OpenFile();
            StreamWriter sw = new StreamWriter(fs);

            // Write and display lines from the data until the end of
            // the data is reached.
            try
            {
                //Debug.WriteLine("CSVWrite processing file " + fileName);
                items = 0;

                foreach (var list in data)
                {
                    foreach (var token in list)
                    {
                        items++;
                        sw.Write(token + ",");
                        //Debug.Write(token + ",");
                    }
                    sw.WriteLine();
                    //Debug.WriteLine();
                }
                sw.Flush();
                sw.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Writestream returned error " + e.Message, " in CSVWrite.");
                throw;
            }

            fs.Close();
            return items;
        }
Example #27
0
        public void main()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.StreamReader sr = new
                   System.IO.StreamReader(openFileDialog1.FileName);
                filename = openFileDialog1.FileName;
                sr.Close();
            }
            else
            {
                return;
            }

            HashSet<string> uzers = new HashSet<string>();
            System.IO.StreamReader file1 = new System.IO.StreamReader(filename);
            while ((line = file1.ReadLine()) != null)
            {
                if (line.IndexOf("Author:") == 0)
                {
                    uzers.Add(line);
                }
            }

            System.Console.WriteLine(uzers.Count);
            foreach (string i in uzers)
            {
                result += "\r\n" + i + "\r\n" + "\r\n";
                Poisk(i);
            }



            Stream myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "txt files (*.txt)|*.txt";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {  
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    save = saveFileDialog1.FileName;
                    myStream.Close();
                }
            }

            System.IO.File.WriteAllText(save, result);            
            file1.Close();
        }
Example #28
0
 private void BtnSave_Click(object sender, EventArgs e)
 {
     SaveFileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.DefaultExt = ".rtf";
     saveFileDialog.Filter = "Rich Text Format(RTF)(*.rtf)|*.rtf";
     if (saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         var file = saveFileDialog.OpenFile();
         RtxInfo.SaveFile(file, RichTextBoxStreamType.TextTextOleObjs);
         file.Close();
         file.Dispose();
     }
 }
Example #29
0
		private void exportButton_Click(object sender, EventArgs e)
		{
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Filter = "XML Document|*.xml";
			sfd.DefaultExt = "xml";
			sfd.AddExtension = true;
			sfd.OverwritePrompt = true;
			sfd.ShowDialog();
			System.IO.Stream stream = sfd.OpenFile();
			foreach (Object o in itemList.SelectedItems)
				XML.exportClassToXml(o, stream);
			stream.Close();
		}
Example #30
0
        /// <summary>
        /// Save road map dialog
        /// </summary>
        /// <param name="roadMap"></param>
        public static void SaveBitmap(Bitmap roadMap)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

              saveDialog.Title = "Save bitmap as...";
              System.Console.WriteLine("Save bitmap as...");
              saveDialog.ShowDialog();
              System.IO.FileStream fileStream = (System.IO.FileStream)saveDialog.OpenFile();
              roadMap.Save(fileStream, System.Drawing.Imaging.ImageFormat.Bmp);
              System.Console.WriteLine("Bitmap saved as: " + saveDialog.FileName);
              System.Console.WriteLine();

              fileStream.Close();
        }