Dear all
I am brand new to C# and have previously only written programs in Javascript, so go easy on me !
I have written an "app launcher" program which reads a text file line by line. Each line is just a path to a program e.g. C:\Users\Matt\Desktop\Gravity.exe
So far, my program can successfully read each line and produce a list of links. As intended, each link appears as the path itself.
The problem I am having is that these links will not work. However they WILL work if they are all just given the same fixed path. I would like each link to use its .Text property as the destination. (please see the comments "works" and "does not work" in my code below). The only error I get is "cannot find the file specified".
I would really appreciate any help on this as I am finding C a lot harder than Javascript !
Thank you
Matt
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; //for reading a text file
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) //on form load
{
int counter = 0;
string line;
string myfile = @"c:\users\matt\desktop\file.txt";
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(myfile);
while ((line = file.ReadLine()) != null)
{
//MessageBox.Show(line); //check whats on each line
LinkLabel mylinklabel = new LinkLabel(); //LinkLabel tells us the type of the object e.g. string mystring ="hello";
mylinklabel.Text = line;
this.Controls.Add(mylinklabel);
mylinklabel.Location = new Point(0, 30 + counter * 30);
mylinklabel.Click += new System.EventHandler(LinkClick);
counter++;
}
file.Close();
}
private void LinkClick(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(this.Text); //doesn't work
//System.Diagnostics.Process.Start(@"C:\Users\Matt\Desktop\gravity.exe"); //works
}
}
}