Autor Beitrag
Spielcind
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 10.01.10 13:16 
Hallo,

ich möchte den Inhalt von DataGridView Zellen in eine Textdatei speichern. Die Daten werden zunächst in einen StringBuilder namens "data" zusammengefasst

ausblenden C#-Quelltext
1:
data.Append((string)dataGridView1[j, i].Value);					


und anschließend abgespeichert:


ausblenden C#-Quelltext
1:
2:
3:
StreamWriter myFile = new StreamWriter("dateiname.txt");
myFile.Write(data.ToString());
myFile.Close();



Leider ist die Datei nicht im ASCII Format abgespeichert.


Nun habe ich hier tinyurl.com/ybsafu7 eine angebliche Lösung des Problems gefunden.


Dies habe ich folgendermaßen umgesetzt:

ausblenden C#-Quelltext
1:
2:
3:
StreamWriter myFile = new StreamWriter(filename);
myFile.Write((Encoding.Default.GetBytes(data.ToString())));
myFile.Close();



In der Textdatei steht jetzt nichts anderes als "System.Byte[]".


Auch wenn ich die Konvertierung bereits beim Anhängen an den StringBuilder durchführe data.Append(Encoding.Default.GetBytes((string)dataGridView1[j, i].Value)); ist das gleiche Problem vorhanden.


Vielleicht kann mir jemand von euch helfen? Wäre sehr nett. Danke schonmal.


Gruß

Daniel


Moderiert von user profile iconKha: Topic aus WinForms verschoben am So 10.01.2010 um 12:38
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 10.01.10 13:37 
Schau dir mal die Parameter des StreamWriter-Konstruktors an ;) ...

_________________
>λ=
Spielcind Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 10.01.10 16:46 
Hallo Kha,


erstmal vielen Dank für deine Hilfe. Leider... funktioniert es trotzdem nicht.

ausblenden C#-Quelltext
1:
StreamWriter myFile = new StreamWriter(sFilename, false, Encoding.ASCII);					


In der Textdatei werden Umlaute jetzt als Fragezeichen dargestellt.


ausblenden C#-Quelltext
1:
StreamWriter myFile = new StreamWriter(sFilename, Encoding.ASCII);					


Hierbei enstehen folgende Fehlermeldungen:

Zitat:
Fehler CS1502: Die beste Übereinstimmung für die überladene System.IO.StreamWriter.StreamWriter(string, bool)-Methode hat einige ungültige Argumente.
Fehler CS1503: 2-Argument: kann nicht von "System.Text.Encoding" in "bool" konvertiert werden.



:( Hast du vielleicht noch einen 2ten Tipp auf Lager? Danke nochmal.


Daniel
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 10.01.10 17:02 
Warum nimmst du auch plötzlich Encoding.ASCII statt Default? Die Amis kennen nunmal so wenig Umlaute ;) .

_________________
>λ=
Spielcind Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 10.01.10 17:24 
Perfekt! ;)


Vielen, vielen Dank und noch ein schönes Wochenendende. :)


Daniel