Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2007, 06:34 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kittysweetheart24
Default please help

Hi!

I have made a button for the OpenFileDialog dialog control and it works fine. But when I select a file to open a file, nothing happens ... What code should I write to open some text files and also ppt files (Power Point Presentations)?

I know that myStream = openFileDialog1.OpenFile() but what should I do with the stream in order to open a selected file in Notepad, for example ? If u can, please send my some examples.

I'm a really beginner in C# and I need your help urgently..

Thanks


Kitty.
 
Old June 1st, 2007, 01:20 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

Kitty,

You might try something like:

private void button1_Click(object sender, EventArgs e)
{
    openFileDialog1.Filter = "Text Files|*.txt";
    openFileDialog1.ShowDialog(this);
    Stream sr = openFileDialog1.OpenFile();

    byte[] buff = new byte[70];
    sr.Read(buff, 0, 60);

    System.Diagnostics.Debug.WriteLine(Encoding.ASCII. GetString(buff));
    sr.Close();
}

This does not take into account end of line or end of stream and just writes the output to the debuggin window.

Good Luck.

What you don't know can hurt you!
 
Old June 2nd, 2007, 01:52 AM
Authorized User
 
Join Date: Mar 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you wanted to open notepad as an external application, you can do this:
Code:
private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    if (ofd.ShowDialog() == DialogResult.OK)
    {
        System.Diagnostics.Process.Start("notepad.exe", ofd.FileName);
    }
}









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.