Autor Beitrag
DevInet
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43

Win XP, Win 7 Prof., Linux Mandriva
C#(VS 2010), Java, php
BeitragVerfasst: Fr 02.07.10 17:12 
Hallo liebe Forumuser.

Ich weiss ich nerve langsam. Aber hier noch ein paar Probs die ich habe.

Zuerst einmal habe ich einen Fehler der sich mir irgendwie nicht erschliesst.
Der Programmcode sieht folgendermassen aus:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Mail_Footer_Frontend
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();

            StreamReader tempread = new StreamReader("templ-aalen.txt", System.Text.Encoding.UTF7, true);
            {
                string line;
                //Überprüfung auf Leerzeilen
                while ((line = tempread.ReadLine()) != null)
                {
                    //Ausgabe der Liste in der ListBox
                    fBox.Items.Add(line);
                }
            }
            tempread.Close();

            StreamReader mread = new StreamReader("mitarbeiter.csv", System.Text.Encoding.UTF7, true);
            {
                string line;
                while ((line = mread.ReadLine()) != null)
                {
                    miBox.Items.Add(line);
                }
            }
            mread.Close();

            StreamReader eread = new StreamReader("events.csv", System.Text.Encoding.UTF7, true);
            {
                string line;
                while ((line = eread.ReadLine()) != null)
                {
                    evBox.Items.Add(line);
                }
            }
            eread.Close();


        }

        private void btn1_Click(object sender, EventArgs e)
        {
            
            
        }

        private void btn2_Click(object sender, EventArgs e)
        {
            string line2 = Convert.ToString(miBox.Text);
           
            StreamWriter tempOne = new StreamWriter("tempone.txt"true);
            tempOne.Write(line2);
            tempOne.WriteLine();
            tempOne.Close();
        }
    }
}



Problem an der ganzen Sache ist, dass wenn ich den Button "btn2" drücke zwar die .txt-Datei erstellt wird, diese aber leer ist.
Dies dürfte aber nicht sein. Bin ich Blind, oder hab ich da was übersehen? Habe die Zeilen gefühlte 100 gecoded, aber immer das selbe Ergebnis.

Help! We need somebody! Help!

mfg
DevInet


Zuletzt bearbeitet von DevInet am Fr 02.07.10 17:22, insgesamt 1-mal bearbeitet
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 02.07.10 17:16 
Hallo!

Bitte wähle einen Thread-Titel, der mehr darüber aussagt, was denn das im Thread behandelte Problem ist. Im Moment kann sich niemand was darunter vorstellen. Danke! :-)

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DevInet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43

Win XP, Win 7 Prof., Linux Mandriva
C#(VS 2010), Java, php
BeitragVerfasst: Fr 02.07.10 17:32 
Hoffe die Überschrift ist verständlicher.
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Fr 02.07.10 17:39 
Hallo,

was soll den miBox darstellen? Du fügst dort Items hinzu.. frägst aber die Eigenschaft Text ab. Ich denke da liegt der Fehler.

Außerdem reicht es, wenn du uns nur den nötigen Code zeigst.

Ich würde auch nicht die StreamReader verwenden, sondern File.ReadAllLines() damit kannst du mit wenig Code und viel lesbarer die Dateien Textweise einlesen.

Gruß
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 02.07.10 17:42 
Ergänzung:

Bitte nie nur mit Dateinamen arbeiten, sondern immer das Verzeichnis mit angeben. Wenn es das Programmverzeichnis sein soll (ganz schlecht, Stichwort Benutzerrechte) kannst Du Application.StartupPath benutzen.

Außerdem würde ich für den StreamWriter (und falls benutzt den StreamReader) die using-Klausel benutzen, die erledigt die Dinge, die man sonst so gerne vergisst ;-)

ausblenden C#-Quelltext
1:
2:
using (var sw = new StreamWriter(@"d:\foo.txt"true))
                sw.WriteLine(textBox1.Text);

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DevInet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43

Win XP, Win 7 Prof., Linux Mandriva
C#(VS 2010), Java, php
BeitragVerfasst: Fr 02.07.10 17:45 
ok, werds ausprobieren.
DevInet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 43

Win XP, Win 7 Prof., Linux Mandriva
C#(VS 2010), Java, php
BeitragVerfasst: Fr 02.07.10 17:54 
Also. miBox ist bei mir die Listbox, in welche die Mitarbeiter.csv geladen wird.
Erstmal soll er mir nur den Inhalt in eine .txt-datei laden.
(Ich weiss, hätte mehr grün sein müssen)
Die .txt-datei wird auch erstellt, aber sie ist wie gesagt leer.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 02.07.10 18:01 
Schau Dir mal in der Doku an, was dort zur Texteigenschaft der Listbox steht, das dürfte Dein Problem lösen :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: DevInet