Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 31st, 2007, 06:34 PM
Registered User
 
Join Date: May 2007
Location: Cluj-Napoca, Cluj, Romania.
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.
Reply With Quote
  #2 (permalink)  
Old June 1st, 2007, 01:20 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
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!
Reply With Quote
  #3 (permalink)  
Old June 2nd, 2007, 01:52 AM
Authorized User
 
Join Date: Mar 2007
Location: , , USA.
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);
    }
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 02:56 AM.


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