OpenFile() public method

public OpenFile ( ) : Stream
return Stream
コード例 #1
1
ファイル: frmBFimp.cs プロジェクト: SoMeTech/hnbthelper
 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();
 }
コード例 #2
0
        private void buttonSave_Click(object sender, System.EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (saveFileDialog.FilterIndex == 2)
                {
                    byte[] data = ChangeDataFormat(currentFormat);
                    if (data != null)
                    {
                        Stream fs = saveFileDialog.OpenFile();
                        fs.Write(data, 0, data.Length);
                        currentFileName = saveFileDialog.FileName;
                        currentFileSize = fs.Length;
                        fs.Close();
                    }
                }
                else
                {
                    ChangeDataFormat(DataFormat.PEM);
                    byte[] data = Asn1Util.StringToBytes(dataStr);
                    Stream fs   = saveFileDialog.OpenFile();
                    fs.Write(data, 0, data.Length);
                    currentFileName = saveFileDialog.FileName;
                    currentFileSize = fs.Length;
                    fs.Close();
                }

                openFileDialog.FilterIndex      = saveFileDialog.FilterIndex;
                openFileDialog.FileName         = saveFileDialog.FileName;
                openFileDialog.InitialDirectory = saveFileDialog.InitialDirectory;
                ShowFileName();
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        private void btnSave_Click_1(object sender, System.EventArgs e)
        {
            try
            {
                FileStream fs;
                saveFileDialog1.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((fs = (FileStream)saveFileDialog1.OpenFile()) != null)
                    {
                        StreamWriter sw = new StreamWriter(fs);
                        sw.Write(txtXml.Text);
                        sw.Close();
                        fs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #5
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();
             }
         }
     }
 }
コード例 #6
0
        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);
                }
            }
        }
コード例 #7
0
        private void SaveLogs_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!Directory.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Properties.Settings.Default.OutputDirectory)))
                {
                    Directory.CreateDirectory(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Properties.Settings.Default.OutputDirectory));
                }
            }
            catch { }
            var dlg = new System.Windows.Forms.SaveFileDialog();

            dlg.InitialDirectory = Properties.Settings.Default.OutputDirectory;
            dlg.FileName         = string.Format("log-{0}.txt", String.IsNullOrEmpty(this.correlationId) ? "no-cid" : this.correlationId);
            dlg.DefaultExt       = "txt";
            dlg.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dlg.FilterIndex      = 1;
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (var writer = new StreamWriter(dlg.OpenFile()))
                {
                    foreach (var item in Logs.Items)
                    {
                        writer.WriteLine(item.ToString());
                    }
                }
            }
        }
コード例 #8
0
        public void CreateOrOpenFile(bool createNewFile)
        {
            //create empty file and get URI for open/save of SAL file.
            if (createNewFile)
            {
                Stream myStream;
                System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

                saveFileDialog1.Filter           = "SimpleAccountLocker files (*.SAL)|*.SAL|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((myStream = saveFileDialog1.OpenFile()) != null)
                    {
                        FileLocationURI = saveFileDialog1.FileName;
                        myStream.Close();
                    }
                }
            }
            //get URI of existing SAL file.
            else
            {
                System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    FileLocationURI = openFileDialog.FileName;
                }
            }
        }
コード例 #9
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();
            }
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: L-Xiah/theVS
        private void button3_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog tempSaveFileDialog = new System.Windows.Forms.SaveFileDialog();

            tempSaveFileDialog.InitialDirectory = "D:\\";
            tempSaveFileDialog.DefaultExt       = ".files";
            tempSaveFileDialog.Filter           = "txt files (*.files)|*.files|All files (*.*)|*.*";
            tempSaveFileDialog.FilterIndex      = 2;
            tempSaveFileDialog.RestoreDirectory = true;

            String tempStrSavePath = "";

            if (tempSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            tempStrSavePath = tempSaveFileDialog.FileName.ToString();
            System.IO.FileStream theFileStream      = (System.IO.FileStream)tempSaveFileDialog.OpenFile();
            ClassFileStream      theClassFileStream = (ClassFileStream)theFileStream;



            String tempStr = @"cv:/df\dsdf\sdsd";

            byte[] value0 = new System.Text.UnicodeEncoding().GetBytes(richTextBox1.Text);
            byte[] value1 = new System.Text.UnicodeEncoding().GetBytes(tempStr);

            theClassFileStream.Write(richTextBox1.Text);
            theClassFileStream.Write(tempStr);
            theClassFileStream.Flush();
        }
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ResultGrid.SelectAllCells();
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                ResultGrid.UnselectAllCells();
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                Clipboard.Clear();

                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                }

                MessageBox.Show("CSV Export complete.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
            }
        }
コード例 #12
0
ファイル: SlideViewer.cs プロジェクト: zganger/SlideViewer
        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();
            }
        }
コード例 #13
0
        /// <summary>
        /// Executes the CSV export process
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // select all cells
                ResultGrid.SelectAllCells();
                // copy data to clipboard
                ResultGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, ResultGrid);
                // clipboard contains data... unselect all cells
                ResultGrid.UnselectAllCells();
                // save data from clipboard to variable
                var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                // data is in variable, clear clipboard
                Clipboard.Clear();

                // create a Save-File Dialog
                var sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter = @"CSV files (*.csv)|*.csv";
                // if dialog displayed successfully
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // write data to file using a StreamWriter
                    var writer = new StreamWriter(sfd.OpenFile());
                    writer.WriteLine(result);
                    writer.Close();
                    MessageBox.Show("CSV Export complete");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("CSV Export failed. \n" + ex.Message);
                Debug.WriteLine(ex);
            }
        }
コード例 #14
0
ファイル: wldFile.cs プロジェクト: kukubadze/Tungsten
        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();
                    }
                }
            }

        }
コード例 #15
0
ファイル: Image.cs プロジェクト: Dahrkael/RMDSCM
        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();
            }
        }
コード例 #16
0
ファイル: Scripting.cs プロジェクト: zixela/l2net
        private void button_savescript_Click(object sender, System.EventArgs e)
        {
            //save script
            this.Enabled = false;

            try
            {
                DialogResult okOrNo;                                                     //dialog return value, if it is DialogResult.OK then everything is OK

                saveFileDialog1.InitialDirectory = Globals.PATH + "\\Scripts";           //Initial dir, where it begins looking at.
                saveFileDialog1.Filter           = "Script Files (*.l2s)|*.l2s";         //this particualr format is for one file type.
                saveFileDialog1.FilterIndex      = 1;                                    //this means that the first description is the default one.
                saveFileDialog1.RestoreDirectory = true;                                 //The next dialog box opened will start at the inital dir.
                okOrNo = saveFileDialog1.ShowDialog();                                   //open the dialog box and save the result.

                if (okOrNo == DialogResult.OK)                                           //if the dialog box displays OK
                {
                    StreamWriter fileout = new StreamWriter(saveFileDialog1.OpenFile()); //create a streamwritter from the stream the dialog box returns
                    StoreScript(fileout);                                                //store everything
                    fileout.Close();                                                     //close the file
                }
            }
            catch
            {
                Globals.l2net_home.Add_Error("ERROR WHILE SAVING SCRIPT!" + System.Environment.NewLine + "Is the script running?");
            }

            this.Enabled = true;
        }
コード例 #17
0
ファイル: DeRangeApp.cs プロジェクト: bright-tools/DeRange
        void ExportConfig(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog saveFileDlg = new System.Windows.Forms.SaveFileDialog();

            saveFileDlg.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDlg.FilterIndex      = 1;
            saveFileDlg.RestoreDirectory = true;
            saveFileDlg.OverwritePrompt  = true;

            if (saveFileDlg.ShowDialog() == DialogResult.OK)
            {
                Stream myStream = null;
                try
                {
                    if ((myStream = saveFileDlg.OpenFile()) != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Config.Top));
                        serializer.Serialize(myStream, config);
                        myStream.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not write file to disk. Original error: " + ex.Message);
                }
            }
        }
コード例 #18
0
ファイル: Form1.cs プロジェクト: Hawriluk/Hawriluk_coursWork
        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();
            }
        }
コード例 #19
0
        /// <summary>
        /// Сохранение плейлиста в файл .aimppl4
        /// </summary>
        /// <param name="songs">Список песен в плейлисте</param>
        public static void SavePlaylist(List <PlaylistElement> songs)
        {
            string playlist = ConfigurationManager.AppSettings["playlist"] + "\n";

            foreach (PlaylistElement song in songs)
            {
                playlist += "\n" + song.FullPath;
            }

            using (swf.SaveFileDialog saveFileDialog = new swf.SaveFileDialog
            {
                Filter = "AIMP playlist (*.aimppl4)|*.aimppl4",
                RestoreDirectory = true
            })
            {
                if (saveFileDialog.ShowDialog() == swf.DialogResult.OK)
                {
                    Stream stream;
                    if ((stream = saveFileDialog.OpenFile()) != null)
                    {
                        StreamWriter sw = new StreamWriter(stream, Encoding.BigEndianUnicode);
                        sw.Write(playlist + "\n");
                        sw.Close();
                        stream.Close();
                    }
                }
            }
        }
コード例 #20
0
        private void CreateNewFile_Click(object sender, RoutedEventArgs e)
        {
            Stream myStream;

            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

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

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    //we must write the file header...
                    byte[] Data = { 0xD4, 0xC3, 0xB2, 0xA1,
                                    0x02, 0x00,
                                    0x04, 0x00,
                                    0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00,
                                    0x00, 0xFF, 0x00, 0x00,
                                    0x01, 0x00, 0x00, 0x00, };
                    myStream.Write(Data, 0, Data.Length);
                    FilePathShow.Text = saveFileDialog1.FileName;
                    myStream.Close();
                }
            }
        }
コード例 #21
0
ファイル: Main.cs プロジェクト: FissionTech/PBL-HR
        /// <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();
                    }
                    
                }
            }


        }
コード例 #22
0
ファイル: MainForm.cs プロジェクト: ebibibi/TimeLog
        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();
                }
            }
        }
コード例 #23
0
ファイル: StoreForm.cs プロジェクト: mar2d2/BarginFinder
        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.
        }
コード例 #24
0
        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());
            }
        }
コード例 #25
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;
            }
        }
コード例 #26
0
ファイル: Form1.cs プロジェクト: santii810/Dam209
      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();
          }
      }
コード例 #27
0
ファイル: Form1.cs プロジェクト: donxnik/MadHackers-DoNxNick
        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);
                }
            }
        }
コード例 #28
0
ファイル: Canasta.cs プロジェクト: emeijori/TIEA212
        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();
                }
            }
        }
コード例 #29
0
ファイル: MainForm.cs プロジェクト: sandormatyi/AVMS
        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 ();
                }
            }
        }
コード例 #30
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();
            }
        }
コード例 #31
0
        /// <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();
                }
            }
        }
コード例 #32
0
ファイル: WarningQueryForm.cs プロジェクト: SaintLoong/PFK
        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();
                }
            }
        }
コード例 #33
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();
 }
コード例 #34
0
 private void onSaveAs(object sender, System.EventArgs e)
 {
     if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         StreamWriter w = new StreamWriter(saveFileDialog1.OpenFile());
         w.Write(textBox1.Text);
         w.Close();
     }
 }
コード例 #35
0
ファイル: Export Menu.cs プロジェクト: K5rovski/MultiGame
        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();
                }
        }
コード例 #36
0
        //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);
                    }
                }
            }
        }
コード例 #37
0
ファイル: Form1.cs プロジェクト: hemanthk119/NeuralNetworks
        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");
        }
コード例 #38
0
ファイル: CSVTools.cs プロジェクト: jdwoodall/Polar-Tool
        //
        // 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;
        }
コード例 #39
0
ファイル: proga.cs プロジェクト: tatyana1202/Logparter
        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();
        }
コード例 #40
0
ファイル: ExportDialog.cs プロジェクト: 2asoft/NoxMapEditor
		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();
		}
コード例 #41
0
ファイル: Packer.cs プロジェクト: rikkit/packer.net
        private void bSave_Click(object sender, System.EventArgs e)
        {
            DialogResult r = sfdResult.ShowDialog(this);

            if (r == DialogResult.OK)
            {
                Stream     s  = sfdResult.OpenFile();
                TextWriter rd = new StreamWriter(s);
                rd.Write(tbResult.Text);
                rd.Close();
                s.Close();
            }
        }
コード例 #42
0
ファイル: SheetForm.cs プロジェクト: Dason1986/Lib
 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();
     }
 }
コード例 #43
0
ファイル: Dialogs.cs プロジェクト: rsirefelt/RoadExtraction
        /// <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();
        }
コード例 #44
0
        private void menuClick_ExportToCSV(object sender, RoutedEventArgs args)
        {
            var dialog = new WinForms.SaveFileDialog();

            dialog.Filter = "Comma-Separated-Value files|*.csv|All files (*.*)|*.*";
            if (dialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                // Open the file chosen by the user, and write the genome to it in CSV format.
                using (var fileStream = dialog.OpenFile())
                {
                    App.document.WriteToCSV(fileStream);
                }
            }
        }
コード例 #45
0
        private void menuClick_SaveSNPDatabase(object sender, RoutedEventArgs args)
        {
            var dialog = new WinForms.SaveFileDialog();

            dialog.Filter = "SNPDatabase files|*.SNPDatabase|All files (*.*)|*.*";
            if (dialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                // Open the file chosen by the user, and write the genome to it in CSV format.
                using (var fileStream = dialog.OpenFile())
                {
                    SNPDatabaseManager.ExportDatabase(fileStream);
                }
            }
        }
コード例 #46
0
        private void saveItemClick(object sender, System.EventArgs e)
        {
            DialogResult buttonClicked = saveFileDialog.ShowDialog();

            if (buttonClicked.Equals(DialogResult.OK))
            {
                Stream       saveStream = saveFileDialog.OpenFile();
                StreamWriter saveWriter = new StreamWriter(saveStream);
                foreach (string line in editData.Lines)
                {
                    saveWriter.WriteLine(line);
                }
                saveWriter.Close();
            }
        }
コード例 #47
0
 private void buttonSave_Click(object sender, System.EventArgs e)
 {
     if (saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         if (saveFileDialog.FilterIndex == 2)
         {
             byte[] data = ChangeDataFormat(currentFormat);
             if (data != null)
             {
                 Stream fs = saveFileDialog.OpenFile();
                 fs.Write(data, 0, data.Length);
                 fs.Close();
             }
         }
         else
         {
             string dataStr = richTextBox.Text;
             byte[] data    = Asn1Util.StringToBytes(dataStr);
             Stream fs      = saveFileDialog.OpenFile();
             fs.Write(data, 0, data.Length);
             fs.Close();
         }
     }
 }
コード例 #48
0
        private void InternalSave(bool bForcePrompt)
        {
            // Prompt the user for the file to save to if this is the first save, or the re-prompt is requested.
            if (bForcePrompt || App.documentSaveStream == null)
            {
                var dialog = new WinForms.SaveFileDialog();
                dialog.Filter = "Personal Genome Explorer files|*.PersonalGenomeData|All files (*.*)|*.*";
                if (dialog.ShowDialog() == WinForms.DialogResult.OK)
                {
                    // Close the old save stream.
                    if (App.documentSaveStream != null)
                    {
                        App.documentSaveStream.Close();
                    }

                    // Open the file chosen by the user for writing.
                    App.documentSaveStream = dialog.OpenFile();
                }
            }

            if (App.documentSaveStream != null)
            {
                // Prompt the user for the password to protect the file with if this is the first save, or the re-prompt is requested.
                if (bForcePrompt || App.document.password == "")
                {
                    var passwordWindow = new PasswordWindow();
                    passwordWindow.Owner = this;
                    passwordWindow.ShowDialog();
                    if (passwordWindow.bOkPressed)
                    {
                        App.document.password = passwordWindow.password;
                    }
                    else
                    {
                        // Abort saving if the password prompt was cancelled.
                        App.document.password = "";
                        return;
                    }
                }

                // Clear the file stream the document was last saved to.
                App.documentSaveStream.Seek(0, SeekOrigin.Begin);
                App.documentSaveStream.SetLength(0);

                // Write the genome to the file.
                App.document.Save(App.documentSaveStream);
            }
        }
コード例 #49
0
        private void _btn_save_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog file = new System.Windows.Forms.SaveFileDialog();
            file.DefaultExt = "gcf";
            file.Filter     = "Gluon configuration file (*.gcf)|*.gcf|All files (*.*)|*.*";
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream stream = file.OpenFile();
                //BinaryFormatter bformatter = new BinaryFormatter();
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationModel));

                Console.WriteLine("Writing model information");
                xmlSerializer.Serialize(stream, configurationTabpage1.GetModel());
                stream.Close();
            }
        }
コード例 #50
0
        private void DownLoadFileShared(string FileName)
        {
            Stream FileStream;
            var    SaveWin = new System.Windows.Forms.SaveFileDialog();

            string[] F_name = FileName.Split('_');
            SaveWin.FileName = F_name[F_name.Length - 1];               // to mane the file names same
            var ret = SaveWin.ShowDialog();

            if (ret == DialogResult.OK)
            {
                if ((FileStream = SaveWin.OpenFile()) != null)
                {
                    UserFile FileToSave = new UserFile("DownloadedFile", ConnectedUser.ClientId);
                    // Code to write the stream goes here.
                    if (ClientFileSystem.filemap.ContainsKey(FileName))
                    {
                        FileToSave = ClientFileSystem.filemap[FileName];
                    }
                    else
                    {
                        ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
                        JsonServiceClient client = new JsonServiceClient(CLOUD_SERVICE_ENDPOINT);
                        foreach (SharedFile file in FileList.sharedFileList)
                        {
                            if (file.filename == FileName)
                            {
                                string owner      = file.owner;
                                string GetFileUrl = string.Format("/file/{0}/{1}/{2}/{3}", ConnectedUser.ClientId, ConnectedUser.Password, FileName, owner);
                                try
                                {
                                    FileToSave = client.Get <UserFile>(GetFileUrl);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                                ClientFileSystem.addFileSynchronized(FileToSave);
                            }
                            FileStream.Write(Encoding.UTF8.GetString(FileToSave.filecontent));
                            FileStream.Close();
                        }
                    }
                }
            }
        }
コード例 #51
0
        //导出电子文件
        private void outputFile()
        {
            if (lstFileExplorer.SelectedItems.Count == 0)
            {
                MB.WinBase.MessageBoxEx.Show("请选择需要导出的电子文件.");
                return;
            }
            try {
                FileDataInfo dataInfo = lstFileExplorer.SelectedItems[0].Tag as FileDataInfo;
                System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();

                saveDlg.DefaultExt = dataInfo.Type;
                string fileType = dataInfo.Type;
                saveDlg.Filter = fileType.Remove(0, 1) + " files (*" + fileType + ")|*" + fileType;;

                if (saveDlg.ShowDialog() == DialogResult.OK)
                {
                    System.IO.Stream outPut = null;
                    if ((outPut = saveDlg.OpenFile()) != null)
                    {
                        if (outPut.Length > 0)
                        {
                            DialogResult re = MB.WinBase.MessageBoxEx.Question("文件已经存在,是否要覆盖原先的文件?");
                            if (re != DialogResult.Yes)
                            {
                                outPut.Close();
                                return;
                            }
                        }
                        System.IO.BinaryWriter binWrite = new System.IO.BinaryWriter(outPut);
                        binWrite.Write(dataInfo.Content);
                        binWrite.Close();
                        if (outPut != null)
                        {
                            outPut.Close();
                        }

                        MB.WinBase.MessageBoxEx.Show("文件导出操作成功!");
                    }
                }
            }
            catch (Exception ex) {
                MB.WinBase.MessageBoxEx.Show("文件导出操作不成功!");
                MB.Util.TraceEx.Write(ex.Message);
            }
        }
コード例 #52
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle clicking the save file button. Save the converted contents to a file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void saveFileButton_Click(object sender, System.EventArgs e)
        {
            if (m_savedOutput == null)
            {
                return;
            }

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream myStream = saveFileDialog.OpenFile();
                if (myStream != null)
                {
                    StreamWriter sw = new StreamWriter(myStream);                     // defaults to UTF-8
                    sw.Write(m_savedOutput.ToString());
                    sw.Flush();
                    myStream.Close();
                }
            }
        }
コード例 #53
0
        private void _btn_save_to_file_Click(object sender, EventArgs e)
        {
            /* Copy listview to array */
            NavigationInstruction[] list = GetNavigationList().ToArray();

            System.Windows.Forms.SaveFileDialog file = new System.Windows.Forms.SaveFileDialog();
            file.DefaultExt = "gnf";
            file.Filter     = "Gluon navigation file (*.gnf)|*.gnf|All files (*.*)|*.*";
            if (file.ShowDialog() == DialogResult.OK)
            {
                Stream stream = file.OpenFile();
                //BinaryFormatter bformatter = new BinaryFormatter();
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(NavigationInstruction[]));

                Console.WriteLine("Writing model information");
                xmlSerializer.Serialize(stream, list);
                stream.Close();
            }
        }
コード例 #54
0
 private void menu_save_Click(object sender, System.EventArgs e)
 {
     System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
     sfd.Title  = "Save Adventure";
     sfd.Filter = "Adventure Builder Files (*.adv)|*.adv";
     sfd.ShowDialog(this);
     try
     {
         Stream strm = sfd.OpenFile();
         AdventurePersistance pers = new AdventurePersistance(strm);
         pers.save(m_graph);
         pers.save(m_settings);
         m_selection = null;
         m_left_down = false;
         strm.Close();
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
コード例 #55
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            dc.RemoveActive();
            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 2;
            saveFileDialog1.RestoreDirectory = true;

            Rect rect = VisualTreeHelper.GetDescendantBounds(canvasImage);
            RenderTargetBitmap rtb = new RenderTargetBitmap((Int32)canvasImage.Width, (Int32)canvasImage.Height, 96, 96, PixelFormats.Pbgra32);
            DrawingVisual      dv  = new DrawingVisual();

            using (DrawingContext dc = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(canvasImage);
                dc.DrawRectangle(vb, null, new Rect(new PointWin(), rect.Size));
            }

            rtb.Render(dv);

            PngBitmapEncoder png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(rtb));

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    png.Save(myStream);
                    myStream.Close();
                }
                DialogResult res = MessageBox.Show("Picture saved in folder", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                DialogResult res = MessageBox.Show("Problem with saving", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #56
0
        private void startNewGame()
        {
            int type = -1;

            switch (selectedGameType)
            {
            default:
            case GameType.FPS: type = Controller.FILE_ADVENTURE_1STPERSON_PLAYER; break;

            case GameType.TPS: type = Controller.FILE_ADVENTURE_3RDPERSON_PLAYER; break;
            }

            Stream myStream = null;

            sfd.InitialDirectory = "c:\\";
            sfd.Filter           = "ead files (*.ead) | *.ead |eap files (*.eap) | *.eap | All files(*.*) | *.* ";
            sfd.FilterIndex      = 2;
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = sfd.OpenFile()) != null)
                {
                    using (myStream)
                    {
                        // Insert code to read the stream here.
                        selectedGameProjectPath = sfd.FileName;
                        if (GameRources.CreateGameProject(selectedGameProjectPath, type))
                        {
                            GameRources.LoadGameProject(selectedGameProjectPath);
                            EditorWindowBase.Init();
                            EditorWindowBase window = (EditorWindowBase)EditorWindow.GetWindow(typeof(EditorWindowBase));
                            window.Show();
                        }
                    }
                    myStream.Dispose();
                }
            }
        }
コード例 #57
0
ファイル: Form1.cs プロジェクト: L-Xiah/theVS
        private void button2_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.SaveFileDialog tempSaveFileDialog = new System.Windows.Forms.SaveFileDialog();

            tempSaveFileDialog.InitialDirectory = "D:\\";
            tempSaveFileDialog.DefaultExt       = ".files";
            tempSaveFileDialog.Filter           = "txt files (*.files)|*.files|All files (*.*)|*.*";
            tempSaveFileDialog.FilterIndex      = 2;
            tempSaveFileDialog.RestoreDirectory = true;

            String tempStrSavePath = "";

            if (tempSaveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            tempStrSavePath = tempSaveFileDialog.FileName.ToString();
            System.IO.FileStream theFileStream = (System.IO.FileStream)tempSaveFileDialog.OpenFile();


            byte[] value0 = new System.Text.UnicodeEncoding().GetBytes(richTextBox1.Text);


            theFileStream.Write(value0, 0, value0.Length);


            tempStrSavePath = "1234567-----";
            byte[] value1 = new System.Text.UnicodeEncoding().GetBytes(tempStrSavePath);
            theFileStream.Position = value0.Length;//设定书写的开始位置为文件的末尾
            theFileStream.Write(value1, 0, value1.Length);
            theFileStream.Flush();



            //System.Diagnostics.Debug.Print(tempStrSavePath);
        }
コード例 #58
0
ファイル: Mainform.cs プロジェクト: MehmetKeskin/-dev2-
 void BackPropagationThreadsFinished()
 {
     if (_bTrainingThreadRuning)
     {
         var msResult = MessageBox.Show("Do you want to save Neural Network data ?", "Save Neural Network Data", MessageBoxButtons.OKCancel);
         if (msResult == DialogResult.OK)
         {
             using (var saveFileDialog1 = new System.Windows.Forms.SaveFileDialog {
                 Filter = "Mnist Neural network file (*.nnt)|*.nnt", Title = "Save Neural network File"
             })
             {
                 if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                 {
                     var fsIn = saveFileDialog1.OpenFile();
                     var arIn = new Archive(fsIn, ArchiveOp.store);
                     _TrainingNN.Serialize(arIn);
                     fsIn.Close();
                 }
             }
         }
         _bTrainingThreadRuning = false;
     }
     return;
 }
コード例 #59
0
ファイル: MainForm.cs プロジェクト: AJLogan/DesignPatterns
        private void createMockButton_Click(object sender, System.EventArgs e)
        {
            IList strategies = new ArrayList();

            if (crashTestDummyCheckBox.Checked)
            {
                strategies.Add(new CrashTestDummyStrategy());
            }
            if (wasCalledCheckBox.Checked)
            {
                strategies.Add(new WasCalledStrategy());
            }
            if (callLogCheckBox.Checked)
            {
                strategies.Add(new CallLoggingStrategy());
            }
            generator.buildMockClass(chooseClassBox.SelectedValue.ToString(), newNameBox.Text, strategies);
            saveFileDialog.InitialDirectory = @"..\..\..";
            DialogResult result = saveFileDialog.ShowDialog();

            //If we found a file
            if (DialogResult.OK == result)
            {
                //Write to the file
                StreamWriter sw = new StreamWriter(saveFileDialog.OpenFile());
                if (csButton.Checked == true)
                {
                    generator.writeCodeAsCSharp(sw);
                }
                else
                {
                    generator.writeCodeAsVB(sw);
                }
                sw.Close();
            }
        }
コード例 #60
0
        private void ExportButton_Click(object sender, System.EventArgs e)
        {
            lblResult.Text = "";
            string    databaseName           = (string)ExportDatabaseList.SelectedItem.ToString();
            bool      scriptDatabase         = chkDatabase.Checked;
            bool      scriptDrop             = this.chkDropCommands.Checked;
            bool      scriptTableSchema      = this.chkTableSchemas.Checked;
            bool      scriptTableData        = this.chkTableData.Checked;
            bool      scriptStoredProcedures = this.chkStoredProcs.Checked;
            bool      scriptComments         = this.chkDescriptiveComments.Checked;
            SqlServer server = new SqlServer(this.txtServer.Text, this.txtUserName.Text, this.txtPassword.Text);

            server.Connect();
            SqlDatabase database = server.Databases[databaseName];

            if (database == null)
            {
                server.Disconnect();
                // Database doesn't exist - break out and go to error page
                MessageBox.Show("connection error");
                return;
            }

            SqlTableCollection           tables = database.Tables;
            SqlStoredProcedureCollection sprocs = database.StoredProcedures;
            StringBuilder scriptResult          = new StringBuilder();

            scriptResult.EnsureCapacity(400000);
            scriptResult.Append(String.Format("/* Generated on {0} */\r\n\r\n", DateTime.Now.ToString()));
            scriptResult.Append("/* Options selected: ");
            if (scriptDatabase)
            {
                scriptResult.Append("database ");
            }
            if (scriptDrop)
            {
                scriptResult.Append("drop-commands ");
            }
            if (scriptTableSchema)
            {
                scriptResult.Append("table-schema ");
            }
            if (scriptTableData)
            {
                scriptResult.Append("table-data ");
            }
            if (scriptStoredProcedures)
            {
                scriptResult.Append("stored-procedures ");
            }
            if (scriptComments)
            {
                scriptResult.Append("comments ");
            }
            scriptResult.Append(" */\r\n\r\n");


            // Script flow:
            // DROP and CREATE database
            // use [database]
            // GO
            // DROP sprocs
            // DROP tables
            // CREATE tables without constraints
            // Add table data
            // Add table constraints
            // CREATE sprocs


            // Drop and create database
            if (scriptDatabase)
            {
                scriptResult.Append(database.Script(
                                        SqlScriptType.Create |
                                        (scriptDrop ? SqlScriptType.Drop : 0) |
                                        (scriptComments ? SqlScriptType.Comments : 0)));
            }


            // Use database
            scriptResult.Append(String.Format("\r\nuse [{0}]\r\nGO\r\n\r\n", databaseName));
            progressBar1.Value = 20;
            progressBar1.Refresh();

            // Drop stored procedures
            if (scriptStoredProcedures && scriptDrop)
            {
                for (int i = 0; i < sprocs.Count; i++)
                {
                    if (sprocs[i].StoredProcedureType == SqlObjectType.User)
                    {
                        scriptResult.Append(sprocs[i].Script(SqlScriptType.Drop | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }
            }

            progressBar1.Value = 30;
            progressBar1.Refresh();
            // Drop tables (this includes schemas and data)
            if (scriptTableSchema && scriptDrop)
            {
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.Drop | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }
            }

            progressBar1.Value = 40;
            progressBar1.Refresh();
            // Create table schemas
            if (scriptTableSchema)
            {
                // First create tables with no constraints
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.Create | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }
            }
            progressBar1.Value = 50;
            progressBar1.Refresh();

            // Create table data
            if (scriptTableData)
            {
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptData(scriptComments ? SqlScriptType.Comments : 0));
                    }
                }
            }

            progressBar1.Value = 60;
            progressBar1.Refresh();
            if (scriptTableSchema)
            {
                // Add defaults, primary key, and checks
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.Defaults | SqlScriptType.PrimaryKey | SqlScriptType.Checks | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }

                // Add foreign keys
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.ForeignKeys | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }
                progressBar1.Value = 70;
                progressBar1.Refresh();
                // Add unique keys
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.UniqueKeys | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }

                // Add indexes
                for (int i = 0; i < tables.Count; i++)
                {
                    if (tables[i].TableType == SqlObjectType.User)
                    {
                        scriptResult.Append(tables[i].ScriptSchema(SqlScriptType.Indexes | (scriptComments ? SqlScriptType.Comments : 0)));
                    }
                }
            }

            progressBar1.Value = 80;
            progressBar1.Refresh();
            // Create stored procedures
            if (scriptStoredProcedures)
            {
                string tmpResult = String.Empty;

                for (int i = 0; i < sprocs.Count; i++)
                {
                    if (sprocs[i].StoredProcedureType == SqlObjectType.User)
                    {
                        tmpResult = sprocs[i].Script(SqlScriptType.Create | (scriptComments ? SqlScriptType.Comments : 0));
                        scriptResult.Append(tmpResult);
                        tmpResult = "";
                    }
                }
            }
            server.Disconnect();
            progressBar1.Value = 100;
            progressBar1.Refresh();
            scriptResult.Append("/*-----END SCRIPT------*/");

            saveFileDialog1.Filter           = "Sql files (*.sql)|*.sql|All files (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;
            Stream myStream;
            string theContent = scriptResult.ToString();

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    StreamWriter wText = new StreamWriter(myStream);
                    wText.Write(theContent);
                    wText.Flush();
                    myStream.Close();
                    lblResult.Text = "File Saved!";
                }
            }
        }