Autor Beitrag
tomycat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Di 18.04.17 20:37 
hallo,
ein Button öffnet die Datei

ausblenden C#-Quelltext
1:
System.IO.StreamReader filel = new System.IO.StreamReader(@"c:\meinprojekt\update.txt", System.Text.Encoding.Default);					


2ter Button:
ausblenden C#-Quelltext
1:
2:
WebClient Clientq = new WebClient();
Clientq.DownloadFile("http://feledi.de/update.txt"@"C:\meinprojekt\update.txt");


Ich klicke den 2ten Button an und es kommt zum Crash. Was muss ich noch hinzufügen, dass ich Button 2 ausühren kann?


Moderiert von user profile iconTh69: Topic aus Basistechnologien verschoben am Mi 19.04.2017 um 09:46
lapadula
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 180
Erhaltene Danke: 10



BeitragVerfasst: Di 18.04.17 20:58 
Was kommt denn da für eine Fehlermeldung?

Der 2. Button funktioniert doch komplett unabhängig vom 1. oder was hast du vor?

Habe das eben schnell ausprobiert, es funktioniert. Habe deinen Quellcode 1:1 kopiert, nur mit meinem Pfad. Vielleicht liegt es an dem, Tipfehler?

Für diesen Beitrag haben gedankt: tomycat
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 18.04.17 21:25 
Du öffnest zuerst eine File per StreamReader. Dann versuchst du per Webclient.DownloadFile auch mit dem File zu arbeiten (da rein zu schreiben) vermutlich während der StreamReader das Fiel noch offen hat. In erster Näherung kann immer nur einer ein File sinnvoll nutzen. Also entweder WebClient.DownloadFile oder ein StreamReader auf ein File öffnen.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Di 18.04.17 21:57 
fehler123 (jpg, 341.84 KB)

Moderiert von user profile iconChristian S.: Bild als Anhang eingefügt
Einloggen, um Attachments anzusehen!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 18.04.17 22:00 
Einloggen, um Attachments anzusehen!
_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.04.17 19:37 
thx, ich bin der Sache von euch nachgegangen, leider habe ich den überblick verloren.
Dann habe ich probiert den Fehler einzugrenzen:

Das ist der Inhalt von meinem Button A.
Einmal klick Button A alles Super, noch mal klick auf Button A, dann bekommen ich die gleiche Fehlermeldung wie oben beschrieben.WebException wurde nicht behandelt Zeile 2

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
 WebClient Client = new WebClient();     
            Client.DownloadFile("http://xxxxxxx.de/update.txt"@"C:\Felkass\update_web.txt");
           
            string[] update_web = new string[1];
            string[] update_local = new string[1];

            int counter = 0;
            string line;

            /////////// WEB 
            System.IO.StreamReader file = new System.IO.StreamReader(@"c:\Felkass\update_web.txt", System.Text.Encoding.Default);
            while ((line = file.ReadLine()) != null)
            {
                update_web[counter] = line;
                counter++;
            }
            //  MessageBox.Show(update_web[0]);
            textBox1.Text += update_web[0];
            textBox1.Text += "...ist die Aktuelle Version";
            textBox1.Text += "\r\n";
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 19.04.17 20:08 
Eine WebException ohne ihre Details ist zu wenig Information. Klicke mal unten im Exception-Dialog auf "Details anzeigen" und schreibe mal, was als Status und was als Response zurückgekommen ist.

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

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.04.17 20:18 
bitte sehr
mehr.jpg (jpg, 86.33 KB)

Moderiert von user profile iconChristian S.: Bild als Anhang eingefügt
Einloggen, um Attachments anzusehen!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 19.04.17 20:27 
Und wenn Du jetzt diese Informationen ansiehst, welche Ideen kommen Dir?

P.S.: Bitte lade Bilder hier im Forum als Anhang hoch, damit sichergestellt ist, dass sie langfristig verfügbar sind.

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

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 20.04.17 11:39 
Idee A
das ganze als thrad / Prozess laufen zu lassen.

Idee B
ich füge einen Befehl ein, der das Öffnen der Text Datei schließt.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 20.04.17 13:04 
Idee A dürfte Dir nichts bringen, denn die Meldung besagt ja, dass die Textdatei durch einen anderen Prozess blockiert wird.

Idee B, wenn ich sie richtig verstanden habe, dürfte in die richtige Richtung gehen: Du musst identifizieren, durch was die Datei gelockt wird und das abstellen. An welchen Stellen in Deinem eigenen Programm greifst Du zum Beispiel auf die Datei zu und schließt sie danach nicht sauber?

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

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: Do 20.04.17 19:09 
Danke fürs hinleiten. Hab die Lösung. In Microsoft Beispiele ist das nicht standartmäsig dabei, deswegen war ich verwirrt. :-)
ausblenden C#-Quelltext
1:
file.Close();					
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 20.04.17 19:26 
Benutze am besten generell die using-Anweisung dafür, also
ausblenden C#-Quelltext
1:
2:
3:
4:
using (StreamReader file = new StreamReader(...))
{

}

So mußt du nicht explizit dafür Close() oder Dispose aufrufen - und dies wird auch bei einer möglichen Exception aufgerufen.

Für diesen Beitrag haben gedankt: tomycat