1

here's my code

Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\ExtractedContent");
using (StreamWriter sw = File.CreateText(Directory.GetCurrentDirectory() + @"\ExtractedContent"))
{
    sw.WriteLine($"TITLE: {extractedTitle[0]}");
    sw.WriteLine("CONTENT:");
    sw.Write(extractedContent[0]);
}`

Error:

Unhandled exception : System.UnauthorizedAccessException: Access to the access path 'C:\Users\"directory of the program"' is denied.

Pac0
  • 21,465
  • 8
  • 65
  • 74
  • 1
    If you're not able to write a file to a directory because of Windows permissions (if that's truly the issue), then the same application probably won't have the rights to _assign_ permissions. – gunr2171 Aug 26 '20 at 13:27
  • Probably [This link](https://stackoverflow.com/questions/34752657/c-sharp-creating-directory-and-setting-the-permissions) will help you – Biju Kalanjoor Aug 26 '20 at 13:35

1 Answers1

1

the problem was that i didn't gave the file a name

using (StreamWriter sw = File.CreateText(Directory.GetCurrentDirectory() + @"\ExtractedContent\file.txt(that's the solution)"))
{
    sw.WriteLine($"TITLE: {extractedTitle[0]}");
    sw.WriteLine("CONTENT:");
    sw.Write(extractedContent[0]);
}