Hey,
So i am trying to write a program in c# that reads in text from a irc chat log file (.txt). This document is located in the following directory: "C:\Users\finnj\AppData\Roaming\HexChat\scrollback\#finnjanssens\#finnjanssens.txt". (#finnjanssens
is the irc channel of my twitch livestream chat). I first tried to just read in the text in a single string and print it out to the console. This is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace TwitchIRC
{
class ReadFromFile
{
static void Main()
{
for (int i = 2; i > 1; i++)
{
string text = File.ReadAllText(@"C:\Users\finnj\AppData\Roaming\HexChat\scrollback\#finnjanssens\#finnjanssens.txt");
Console.WriteLine(text);
}
}
}
}
I then had the problem that the program wasnt authorized to access the path of the log. I solved this by adding a app.manifest item and replacing the following line:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
with
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
This solved thre problem of the unauthorized access, but now i get a "IOexception was unhandled" error. This is probably because Hexchat (my irc client) is writing to the textdocument at the same time. If i close my irc client it works just fine,
but i need my irc client to write to the log, else the program has no purpose. Is there a way to get around this? Thanks!