Dlaczego jeśli nie ma takiej ścieżki (program ma ją stworzyć) wywala błąd?
using System;
using System.IO;
using System.Collections.Generic;
namespace Projekt
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Proba\";
string fileName = "index.html";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (!File.Exists(path + fileName))
File.Create(path + fileName);
List<string> lines = new List<string>();
lines.Add("1");
lines.Add("2");
File.WriteAllLines(path + fileName, lines);
}
}
}
BŁĄD: "Proces nie może uzyskać dostępu do pliku „C:\Proba\index.html”, ponieważ jest on używany przez inny proces." Nie rozumiem, tylko ten program wykonuje to .exe