Hi All
I have a small app. What is does it reads an html file for certain keywords (like e9, e5, e21, etc.) When any of those lines are found it must add a link in html format into the file. Except you will see that the folder locations differ.
For example, the folder structure is Test Images, inside ther are folders called e2, e5, etc. In them are images. When the link is created it must automaticaly input the correct location. Say if e2 is found then the link must be like this:
<a href='Test Images\e2'><img src='Camera.png' style='position: absolute; top: 185; left: 1050;' border='0' alt='Hello'></a></map></body></html> (Note the e2)
Below is the code I have so far, so can anyone help me perhaps?
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;
using System.Text.RegularExpressions;
namespace TrueViewApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string fName = @"Y:\WorleyParsons\Sasol Unit 17\Submission Data\Tru-View\Unit17TruViewInterface\TruView\Unit17\SiteMap.htm";//path to text file
StreamReader testTxt = new StreamReader(fName);
string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end
testTxt.Close(); //Closes the text file after it is fully read.
string regMatch = @"e";//string to search for inside of text file. It is case sensitive.
if (Regex.IsMatch(allRead, regMatch))//If the match is found in allRead
{
StreamWriter SW;
SW = File.AppendText("Y:\\WorleyParsons\\Sasol Unit 17\\Submission Data\\Tru-View\\Unit17TruViewInterface\\TruView\\Unit17\\SiteMap.htm");
SW.WriteLine(@"<a href='Test Images\e3'><img src='Camera.png' style='position: absolute; top: 185; left: 1050;' border='0' alt='Hello'></a></map></body></html>");
SW.Close();
MessageBox.Show("Line successfully Appended");
Application.Exit();
}
else
{
MessageBox.Show("not found");
}
}
}
}