i'm trying to create a json file if it doesn't exist, and then write all lines to it. The creation of the file works, but the problem i have is that File.WriteAllLines says "the process cannot access the file because it is being used by another process".
Here's my code:
public void generateFolderFiles(string folderToSearch, string fileToEdit) {
string[] filesToSearch = Directory.GetFiles(folderToSearch);
string completeJson = "";
for(int i=0;i<filesToSearch.Length;i++) {
try {
File.Delete(fileToEdit);
File.Create(fileToEdit);
} catch(Exception e){}
string[] fsLines = File.ReadAllLines(filesToSearch[i]);
string fsText = string.Join("", fsLines);
fsText=fsText.Replace("[", "").Replace("]", "");
completeJson+=fsText;
}
completeJson="["+completeJson+"]";
string[] lnes = new string[1]{completeJson};
File.WriteAllLines(fileToEdit, lnes);
}