C# Datei Explorer

07/11/2013 08:32 lukas_k#1
Edit: Problem wurde gelöst: [Only registered and activated users can see links. Click Here To Register...]


Hayhou,

vorweg sei gesagt ich bin blutiger Anfänger was programmieren angeht, also bitte seid gnädig falls die Frage offensichtlich ist, ich stehe grade auf'm Schlauch :o

Ich hab als Übung [Only registered and activated users can see links. Click Here To Register...] so verändert, dass er einem richtigen Explorer schon näher kommt und ich alle Festplatten etc. sehe. Klappt soweit auch wunderbar, das war nicht das Problem. Jetzt will ich allerdings noch etwas mehr verändern und möchte, dass eine Datei bei Doppelklick mit dem Standardprogramm geöffnet wird. Ich hatte vor das mit der Methode Process.Start() zu machen.

Damit liste ich die Dateien im ausgewählten Verzeichnis auf. Mein Problem ist jetzt nur, dass ich nicht weiß wie ich den Dateipfad an Process.Start() übergeben soll.

Code:
foreach (string Fname in Files)
                {
                    subinfo[0] = GetFileName(Fname);
                    subinfo[1] = GetSizeinfo(Fname);
                    subinfo[2] = GetTypeinfo(Fname);
                    subinfo[3] = GetFileModDate(Fname);
                    subinfo[4] = GetFileCreDate(Fname);
                    ListViewItem FItems = new ListViewItem(subinfo);
                    listView1.Items.Add(FItems);
                }
Hoffe mir kann dabei jemand nen kleinen Tipp geben, wenn auch nur wonach ich Googeln soll, ich komm grade echt nicht weiter. :o

Grüße
RaZoR
07/11/2013 08:41 Syc#2
Ich geh mal davon aus, dass Fname den Dateipfad enthält?

Dann kannst du

a) den Dateipfad mit in der ListView ausgeben und dann von dort aushernehmen oder
b) einfach die ganzen Fname irgendwie aufrufen, z.b. wenn du sie nochmal in ein array packst
07/11/2013 08:42 »Barney«#3
Why don't you use a simple DataGridView ?

This is a simple example from a MySQL query form:

Code:
this.table = await Server.DBManager.Query(cmd);
this.dataGridView1.DataSource = table;
this.dataGridView1.Refresh();
Where this.table is System.Data.DataTable ;)

sorry for not giving a better example, i'm a bit busy. consider this as a simple advice, group the files' information in a table :)
07/11/2013 10:08 SwarN#4
Quote:
Originally Posted by <RaZoR> View Post
Code:
foreach (string Fname in Files)
                {
                    subinfo[0] = GetFileName(Fname);
                    subinfo[1] = GetSizeinfo(Fname);
                    subinfo[2] = GetTypeinfo(Fname);
                    subinfo[3] = GetFileModDate(Fname);
                    subinfo[4] = GetFileCreDate(Fname);
                    ListViewItem FItems = new ListViewItem(subinfo);
                    listView1.Items.Add(FItems);
                }
Code:
foreach (string Fname in Files)
                {
                    subinfo[0] = GetFileName(Fname);
                    subinfo[1] = GetSizeinfo(Fname);
                    subinfo[2] = GetTypeinfo(Fname);
                    subinfo[3] = GetFileModDate(Fname);
                    subinfo[4] = GetFileCreDate(Fname);
                    subinfo[5] = Fname; // <- if its the full path if not add here the full path example: "C:/Temp/test.exe"
                    ListViewItem FItems = new ListViewItem(subinfo);
                    listView1.Items.Add(FItems);
                }
Code:
        ProcessStartInfo startInfo = new ProcessStartInfo();
	startInfo.FileName = listView1.SelectedItem.Item[5];   // <-- could be that's not correct but simply you need from you selected ListView entry the 5th item with fullpath.
	startInfo.Arguments = ""; // <-- only needed to call with a program with arguments
	Process.Start(startInfo); // <-- starts the programm
07/11/2013 10:59 lukas_k#5
Edit: Problem gelöst, danke an alle :)

Ich hab jetzt eine neue Spalte hinzugefügt, in der der Dateipfad steht:
Code:
foreach (string Fname in Files)
                {
                    subinfo[0] = GetFileName(Fname);
                    subinfo[1] = GetSizeinfo(Fname);
                    subinfo[2] = GetTypeinfo(Fname);
                    subinfo[3] = GetFileModDate(Fname);
                    subinfo[4] = GetFileCreDate(Fname);
                    subinfo[5] = GetFilePath(Fname);
                    ListViewItem FItems = new ListViewItem(subinfo);
                    listView1.Items.Add(FItems);
GetFilePath sieht dann so aus, der Pfad wird in der Spalte auch angezeigt:
Code:
public string GetFilePath(string path)
        {
            FileInfo fp = new FileInfo(path);
            return path;
        }
Hier dann noch was beim Doppelklick passiert:
Code:
 
void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("Die Datei wird jetzt mit dem Standardprogramm geöffnet");  

            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = listView1.SelectedItems[0].SubItems[5].Text;
            Process.Start(startInfo);
        }
07/11/2013 11:43 Syc#6
PHP Code:
listView1.SelectedItems[0].SubItems[5].Text 
bei fehlern, schauen, was der fehler ist und sich selber informieren, in dem fall über die listview
07/14/2013 17:02 xxfabbelxx#7
closed on request