Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 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 April 18th, 2005, 09:13 AM
Authorized User
 
Join Date: Feb 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying a text file in a web form.

I am having difficulty displaying a text file in a web form or windows form. I can do this for an Access data base I created and and it displays the table - how is this different and what controls should I be using to display the hello.txt file? Can anyone help? Thank you,Joe
 
Old April 18th, 2005, 09:55 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Look into the classes in the System.IO namespace. There you'll find classes that deal with the file system and can use one of them to open a file and read it into your program.

-Peter
 
Old April 18th, 2005, 11:47 AM
Authorized User
 
Join Date: Feb 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will do this thank you Pete. I cross posted this because on reflection I thought the beginners forum would be more appropriate.
Please advise on what to do in an instance such as this. I am trying to work with your answer.

 
Old April 18th, 2005, 01:27 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
            string s=string.Empty;
            StreamReader reader=null;
            try
            {
                reader=new StreamReader(@"d:\File.txt",Encoding.ASCII);
                //do the stuff
                s=reader.ReadToEnd();
            }
            catch(Exception exp)
            {
                //...
            }
            finally
            {
                //free the resource
                reader.Close();
            }


_____________
Mehdi.
software student.
 
Old April 18th, 2005, 02:33 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

boksi,

A moderator can move it for you, which I will do. (The topic ID won't change so the thread will stay intact.)
 
Old April 18th, 2005, 04:14 PM
Authorized User
 
Join Date: Feb 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Peter.

 
Old April 19th, 2005, 10:49 AM
Authorized User
 
Join Date: Feb 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried the following code in a class which I added to the WebForm1.cs called TextFromFile...it compiles but does not
show my text file in a browser when I do a start without debugging.

using System;
using System.IO;
namespace WebApplication4
{
    /// <summary>
    ///
    /// </summary>



public class TextFromFile
{
    private const string FILE_NAME = "blah.txt";
    public static void Main(String[] args)
    {
        if (!File.Exists(FILE_NAME))
        {
            Console.WriteLine("{0} does not exist.", FILE_NAME);
            return;
        }
        StreamReader sr = File.OpenText(FILE_NAME);
        String input;
        while ((input=sr.ReadLine())!=null)
        {
            Console.WriteLine(input);
        }
        Console.WriteLine ("The end of the stream has been reached.");
        sr.Close();
    }
}

            //
            // TODO: Add constructor logic here
            //
        }









Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a text file in a web form. boksi ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2005 10:54 AM
Displaying images stored in a DB on a Web Form Trevor Miles ASP.NET 1.0 and 1.1 Basics 0 January 7th, 2005 04:14 AM
displaying png in web form dotnettergirl ASP.NET 1.0 and 1.1 Professional 0 July 16th, 2003 10:15 PM
displaying png in web form dotnettergirl Pro VB.NET 2002/2003 0 July 16th, 2003 10:15 PM





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