Search code examples
c#internet-explorerexceptionadd-on

File.AppendAllText throws FileNotFoundException


I am working on Internet explorer add-on, I wrote a dll that attached to the browaswer, Ihave some event, inside of ot I am writing to some text file with File.AppendAllText, this throws FileNotFoundException, I am using AppendAllText in other places in my code, and there if the file is not exist it creates a new file, my question is why this exception throwen and how can I avoid that.

I have found this answer, but it doesnt say how to avoid the error (i.e to write the file without getting this exception), also didn't understad that this is a "documentation error"

Here file fath:

static string assem = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
static string logPath = Path.Combine(assem, "Log.log");

Here the line that thows the error:

File.AppendAllText(logPath, "some text" + Environment.NewLine);

Here the exception:

enter image description here


Solution

  • Probably IE blocks the extension to write to a local file, try to uncheck the "Protected mode" int the browser

    Tools --> Internet Options --> Security --> unckeck "Enable Protected Mode"