WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   c# multiselect dateien öffnen (http://www.wcm.at/forum/showthread.php?t=167214)

porli 01.06.2005 22:26

c# multiselect dateien öffnen
 
öffne in c# über den openFileDialog mehrere Dateien!

Code:

OpenFileDialog openFileDialog1 = new OpenFileDialog();
                        // save the last directorie the user has chosen
                        if (last_dir != "0") openFileDialog1.InitialDirectory = last_dir;
                        else openFileDialog1.InitialDirectory = "c:\\" ;
                        openFileDialog1.Filter = "txt files (*.txt)|*.txt|htm files (*.htm)|*.htm|html files (*.html)|*.html" ;
                        openFileDialog1.FilterIndex = 2 ;
                        openFileDialog1.RestoreDirectory = true ;
                        last_dir = openFileDialog1.FileName.ToString();
                        openFileDialog1.Multiselect = true;

und jetzt will ich wissen wie viel dateien gewählt wurden.... sollte doch mit:
Code:

number_of_file_names = openFileDialog1.FileNames.Length;
funktionieren!
doch es kommt immer 0 zurück! was mach ich falsch?
habs auch schon mit GetLength versucht! gleiches ergebnis!

bidde um hilfe!

delphirocks 02.06.2005 08:40

Code:


OpenFileDialog openFileDialog1 = new OpenFileDialog();
                        // save the last directorie the user has chosen
                        openFileDialog1.InitialDirectory = "c:\\" ;
                        openFileDialog1.Filter = "txt files (*.txt)|*.txt|htm files (*.htm)|*.htm|html files (*.html)|*.html" ;
                        openFileDialog1.FilterIndex = 2 ;
                        openFileDialog1.RestoreDirectory = true ;
                       
                        openFileDialog1.Multiselect = true;

                        openFileDialog1.ShowDialog();
                        int i=openFileDialog1.FileNames.Length;

Also in i steht die Anzahl der selektierten Files. Wo ist dein Showdialog Aufruf ?

porli 02.06.2005 23:01

danke! hat gefunzt!
ich habs einfach 2 zeilen zu frü gschrieben!

porli 05.06.2005 18:18

und ich steh scho wieder vor einem prob:

und zwar hab ich glaub ich irgendein buffer problem!
Ich hab eine html datei, die ich zeile für zeile ausles und in eine neue schreib!
und ich hab den punkt link entfernen hinzugefügt, der auch wunderbar funktioniert! nur seitdem schreibt er mir am ende der datei die letzten paar zeilen noch einmal hin! und ich krübel scho seit 2 std warum und komm nicht drauf!

Code:

//MessageBox.Show("working");
                                label_status.Text="working";
                                // copies the htm_File in the temp_File, overwrite if exists
                                File.Copy(array_file_names[i],temp_File,true);
                                // open temp_File for reading
                                FileStream fs = File.OpenRead(temp_File);
                                // create streamReader instanz, combine with stream
                                StreamReader sr = new StreamReader(fs);
                                // open htm_File for writing
                                FileStream fs1 = File.OpenWrite(array_file_names[i]);
                                // create streamWriter instanz, combine with stream
                                StreamWriter sw = new StreamWriter(fs1);
                               
                                //while not eof
                                while ((sr.Peek())!=-1)
                                {
                                        // store one line in zeile
                                        string zeile = sr.ReadLine();
                                       
                                        string titel = "<title>" + textBox_titel.Text.ToString();
                                        titel += "</title>";
                                        // if zeile is equal with textBox_replace_string then replace it with
                                        // the string
                                        if (zeile.Equals(textBox_search_string.Text.ToString()))
                                        {
                                                //MessageBox.Show("gefunden,gefunden");
                                                zeile = textBox_replace_string.Text.ToString();
                                                label_status.Text="string found";
                                                timer_status.Interval = 2500;
                                                timer_status.Start();
                                        }

                                        if (checkBox_titel.Checked)
                                        {
                                                if (zeile.StartsWith("<title>"))
                                                {
                                                        MessageBox.Show("titel");
                                                        zeile = titel;
                                                }
                                        }

                                        if (checkBox_link.Checked)
                                        {
                                                if ((zeile.StartsWith("
")))
                                                {
                                                        MessageBox.Show("link");
                                                        int end_of_link_line = zeile.IndexOf(">",1,zeile.Length-2);
                                                        button_work.Text = end_of_link_line.ToString();
                                                        //zeile.TrimStart(zeile[20]);
                                                        zeile = zeile.Remove(0,end_of_link_line+1);
                                                        //button_work.Text = zeile.ToString();
                                                }
                                        }
                                       
                                        sw.WriteLine(zeile);
                               
                                }
                                // write buffer
                                //sw.Flush();
                                sw.Close();
                                sr.Close();

und so sieht die html datei aus:
Code:

<td align="center">


[img]../Bilder/P1010437_JPG.jpg[/img]</a>

</td>
</tr>
</table>
</body>
</html> //ab da schreibt er immer was dazu!?!
r/P1010437_JPG.jpg" border=0></a>

</td>
</tr>
</table>
</body>
</html>


porli 07.06.2005 08:45

keiner ne ahnung`?


Alle Zeitangaben in WEZ +2. Es ist jetzt 03:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag