Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using new,open, exit under file on menu

Posted on 2009-07-14
4
Medium Priority
?
217 Views
Last Modified: 2013-12-17
Hello,
I am starting to work on a form in C#. Under FILE on menu:
I have New
          Open
          Save
          Exit
I want to be able to create a new HTML file
                                 open a existing HTML file
                           and save an existing HTML file
I have pasted code I have so far
Do I need to set default property to HTML - or should I code differently?
thank you
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
namespace menu1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
//exit on menu
 
        private void eToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
//open on menu 
 
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string myContent;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StreamReader reader = new StreamReader(openFileDialog1.FileName);
                myContent = reader.ReadToEnd();
                reader.Close();
            }
            
        }
//save on menu
 
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StreamWriter writer = new StreamWriter(saveFileDialog1.FileName);
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
 
        }
    }

Open in new window

0
Comment
Question by:davetough
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 2000 total points
ID: 24851454
I'm not sure I understand what the problem is, but I'm assuming you want to ensure that the user only can select HTML files.

On openFileDialog1 and saveFileDialog1 set the following properties:

DefaultExt = html
Filter = HTML files|*.html
0
 

Author Comment

by:davetough
ID: 24851559
yes - thank you - I was not sure about filter
lastly- I am  not sure of how to write code for New - to create a new html
0
 
LVL 21

Expert Comment

by:Craig Wagner
ID: 24855323
What are the semantics of File -> New? What should it do? Usually when you do a File -> New operation it creates a new in-memory document. Assuming you have some sort of control on the form to let the user enter data into, File -> New should probably clear that control of its data.
0
 

Author Comment

by:davetough
ID: 24856168
I want to just create a empty htm file- you are correct about clearing data- I am going to have to think about what you said- thank you
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question