Autor Beitrag
DenniZ
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

Win XP
C# (VS 2k5)
BeitragVerfasst: Di 13.03.07 21:48 
Hi :)

Ich schon wieder *g*, ich weis, Anfänger, hab Google benutzt, habe auch einiges gefunden doch es will nicht funktionieren!

Also, ich möchte, beim Startup prüfen ob eine Datei existiert. Wenn nicht, dann soll er sie erstellen. Das Problem liegt beim checken, ich bin schon "recht weit", für mich Persönlich ist der Code fertig doch es kommt immernoch ein Error, hier mein Code:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
private void FormGAL_Load(object sender, EventArgs e)
        {
            
            if (File.Exists(Application.StartupPath + (@"\appPath1.txt")));
            {
                string Path1 = Application.StartupPath + (@"\appPath1.txt");
                StreamReader sr1 = new StreamReader(Path1);
                string AppPath1 = sr1.ReadLine().ToString();

                richTextBox1.Text = AppPath1;

                sr1.Close();
            }
       }


Der Fehler, er konnte sie nicht finden *lol* was ja auch mehr oder weniger beabsichtigt ist!
"Could not find file 'F:\...\bin\Debug\appPath1.txt'."
Er tritt in der Zeile "StreamReader sr1=..." auf, markiert bei Path1 ;)

Bitte um Hilfe, bekomme das wirklich nicht gebacken!
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Mi 14.03.07 10:07 
Mach mal das Semikolon in der zeile mit dem If weg... Du hast nämlich sonst n leeren If-Block...

mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mi 14.03.07 10:35 
Hallo,

r2c2 hat recht; das führt zum Fehler. Ich möchte noch kleinere Änderungen vorschlagen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
//  das Zusammensetzen des Pfades wird doppelt vorgenommen,
//  deshalb besser vorziehen; dafür kann das Problem mit vielleicht
//  doppeltem Backslash vermieden werden
string Path1 = Path.Combine(Application.StartupPath, "appPath1.txt");
if (File.Exists(Path1))
{
    StreamReader sr1 = new StreamReader(Path1);

    //  die doppelte String-Zuweisung ist nicht erforderlich
    richTextBox1.Text = sr1.ReadLine().ToString();

    sr1.Close();
}

Gruß Jürgen
DenniZ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

Win XP
C# (VS 2k5)
BeitragVerfasst: Mi 14.03.07 13:37 
Danke euch beiden schonmal, werde das in paar Minuten mal umsetzen, ich editiere dann den Beitrag ;)

@Jütho

"string Path1 = Path.Combine(Application.StartupPath, "appPath1.txt");"
Wird nicht funktionieren, man muss vor dem appPath1.txt einen Backslash setzen, mindestens, dann muss auch noch ein @ hin, ansonsten 2 Stück sonst kommt so raus zum Beispiel:

C:\Programme\ProgrammnameappPath1.txt
Ein Slash muss ;)

€dit:
Danke :) Funktioniert nun einwandfrei! *happy*
r2c2
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 324
Erhaltene Danke: 2

Linux

BeitragVerfasst: Mi 14.03.07 15:00 
user profile iconDenniZ hat folgendes geschrieben:

"string Path1 = Path.Combine(Application.StartupPath, "appPath1.txt");"
Wird nicht funktionieren, man muss vor dem appPath1.txt einen Backslash setzen, mindestens, dann muss auch noch ein @ hin, ansonsten 2 Stück sonst kommt so raus zum Beispiel:

C:\Programme\ProgrammnameappPath1.txt
Ein Slash muss ;)

Ähm... nö. Probiers aus. Path.Combine macht das schon richtig...

mfg

Christian

_________________
Kaum macht man's richtig, schon klappts!
DenniZ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

Win XP
C# (VS 2k5)
BeitragVerfasst: Mi 14.03.07 15:10 
Ok ok :oops:

Gebe mich geschlagen ;) hab Path.Combine noch nie verwendet ;)

Achja, Frage beantwortet, Thread auch so markiert, closed? ;)