Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
U

User 8327598

@User 8327598
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What am I doing wrong?
    U User 8327598

    The first code works, however I need to be able to read contents of multiple files from a particular directory. Start simple and build from there I figure. Doing something wrong somewhere, as the 2nd code only brings up the dos window without any data.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    namespace readtest
    {
    class Program
    {
    static void Main(string[] args)
    {

            StreamReader sr = new StreamReader("C:\\\\Users\\\\Random.txt");
                string str = sr.ReadLine();
                
                string\[\] words = str.Split('|');
                foreach (string word in words)
                {
                    Console.WriteLine(word);
                } Console.ReadKey();
            }
        }
    }
    

    This is the one I need to have working. I must be structuring something wrong. I've tried different ways, but no luck.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    namespace ConsoleApplication2
    {
    class Program
    {
    static void Main(string[] args)
    {
    string[] files = Directory.GetFiles("C:\\Users", ".txt");
    foreach (string file in files)
    {
    StreamReader sr = new StreamReader(file);
    string str = sr.ReadLine();

                    {
                        Console.WriteLine(file);
                    }
                } Console.ReadKey();
    
            }
        }
    }
    
    C# csharp linq question lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups