6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » Windows Azure » Unable to Save
       
Author Reply
My name
posted 9 posts
since Jan 25, 2006 
from

Unable to Save

  Posted on: 07 Feb 2012       
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)
        {


        }




    }


}




Frogleg
posted  808 posts
since  Aug 13, 2010 
from  Australia

 Re: Unable to Save
  Posted on: 08 Feb 2012        0  
When using savefile and openfile dialogs the usual way is

if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}

if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//do whatever
}

Richtextbox has a load feature:

richTextBox1.LoadFile(openFileDialog1.FileName);

and save feature:

RichTextBox1.SaveFile(saveFileDialog1.FileName);
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Unable to Save
  Posted on: 08 Feb 2012        0  
Thanks I have tried this but it does not work as I dont have a TextBox1 declared. 


Error1The name 'RichTextBox1' does not exist in the current context




Frogleg
posted  808 posts
since  Aug 13, 2010 
from  Australia

 Re: Unable to Save
  Posted on: 08 Feb 2012        0  
That openfile dialog was a code snippet I had - I pasted it into the post window - just remove textbox1 etc.
The save file will be the name of the richtextbox
ie
rtb.SaveFile("myfile.rtf");
So whatever you call your richtextbox, just add    .SaveFile("myfile.rtf");

If you have more trouble - upload your whole project so I can run through it - I don't tend to read long code questions for the reason
A: It's easier to read in the ide(code window)
B: I can debug your code

As a side note
I would suggest investing in a tutorial book to help you with the basics of C# programming
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Unable to Save
  Posted on: 08 Feb 2012        0  
Ok I have done what I think is right and now its saving the file, but its blank.  And does not open a file when I try to open it 

I have attached the code

Frogleg
posted  808 posts
since  Aug 13, 2010 
from  Australia

 Re: Unable to Save
  Posted on: 09 Feb 2012        0  
Having the whole project is easier
See what you think
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Unable to Save
  Posted on: 09 Feb 2012        0  
Ok thanks.. Essentially i can see what you have done, but it seems like you have disabled the save button unless a document is opened first and then it enables.. But if you run the program fir the first time the save button is disabled ..  so if i start typing and try to save it , I cant ?

 Just out of interest what is the reason for this

If I click on a blank menu option under file then I get this error. 

Empty Path name is not legal. 


enableSave(true);// enable save buttons
            NewTab(false, Properties.Settings.Default.lastSave1);//create new tabpage and richtextbox
            rtb.LoadFile(Properties.Settings.Default.lastSave1);
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Unable to Save
  Posted on: 09 Feb 2012        0  
Ok I see that you had made Save disabled at startup. I have changed it and its ok now.. Nice touch with the "recent" docs.. I will have a look at that more. Now to figure the printing as well :-)
Frogleg
posted  808 posts
since  Aug 13, 2010 
from  Australia

 Re: Unable to Save
  Posted on: 09 Feb 2012   Accepted Answer     0  
I did not fully go into the save button routine - I figured you could sort it out
In the blank menu, I forgot to put code in to stop if no saved setting

should be

private void bttnLastSave1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Properties.Settings.Default.lastSave1))
{
return;
}
enableSave(true);// enable save buttons
NewTab(false, Properties.Settings.Default.lastSave1);//create new tabpage and richtextbox
rtb.LoadFile(Properties.Settings.Default.lastSave1);
}
If you need help with printing - start a new post
       
Top Articles
View all »
6 Months Free & No Setup Fees ASP.NET Hosting!
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved