8
Reply

Unable to Save

My name 0

My name 0

Feb 7 2012 5:55 PM
1.6k
hello Wonder if anyone can help.  I am in the process of putting together a Tabbed NotePad and When I try to do the Save File I get the following Errors :



The name 'FileSystem' does not exist in the current context 
The name 'OpenMode' does not exist in the current context

This is the code I am trying to use to save information from a Richtext Box.

   SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
            SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Files|*.txt";
            SaveFileDialog1.ShowDialog();
            FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output);
            FileSystem.PrintLine(1, ((RichTextBox)tabControl1.SelectedTab.Controls.item(0)).Text);
            FileSystem.FileClose(1);

What am I doing wrong.. Below is the code for the whole program


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        public static string strTitle = "NotePad";
       


        public void SaveFile(string FileName)
        {
           
        }








        private void Form1_Load(object sender, EventArgs e)
        {


            //This is the main Form Load routine


            this.Text = strTitle;


            NewTab();  // This runs the routine to create a new text tab when the program starts up




        }


        private RichTextBox GetRichTextBox()
        {
            RichTextBox rtb = null;
            TabPage tp = tabControl1.SelectedTab;


            if (tp != null)  //If a tab is selected
            {
                rtb = tp.Controls[0] as RichTextBox;
            }


            return rtb;
        }








        public void NewTab()
        {
            if (tabControl1.TabPages.Count != 100) // Count the amount of Tabs
            {


                this.Text = "Untitled - " + strTitle;


                // This Subroutine will create a new Tab and RichTextBox
                TabPage tp = new TabPage("untitled.txt");
                tp.Tag = "Untitled";


                RichTextBox rtb = new RichTextBox();
                rtb.Dock = DockStyle.Fill;


                tp.Controls.Add(rtb);
                tabControl1.TabPages.Add(tp);


            }
            else
            {
                MessageBox.Show("You have reached the limit on tabs.");


            }


        }


        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewTab();
        }


        private void newToolStripButton_Click(object sender, EventArgs e)
        {
            NewTab();


        }






        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Cut();


        }


        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Copy();


        }


        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Paste();
        }


        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().SelectAll();


        }


        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Undo();


        }


        private void cutToolStripButton_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Cut();
        }


        private void copyToolStripButton_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Copy();
        }


        private void pasteToolStripButton_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Paste();
        }








        private void closeTabToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = tabControl1.TabIndex;
            tabControl1.TabPages.RemoveAt(index);
        }


        private void redoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GetRichTextBox().Redo();


        }


        private void openToolStripButton_Click(object sender, EventArgs e)
        {
           
        }


        private void saveToolStripButton_Click(object sender, EventArgs e)
        {




            SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
            SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Files|*.txt";
            SaveFileDialog1.ShowDialog();
            FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output);
            FileSystem.PrintLine(1, ((RichTextBox)tabControl1.SelectedTab.Controls.item(0)).Text);
            FileSystem.FileClose(1);
        }


        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {


        }




    }


}





Answers (8)