Проблема при создании и записи в текстовый файл с использованием С# ⇐ C#
-
Anonymous
Проблема при создании и записи в текстовый файл с использованием С#
I try to create a text file and write some data to it. I am using the following code:
public void AddNews(string path,string News_Title,string New_Desc) { FileStream fs = null; string fileloc = path + News_Title+".txt"; if (!File.Exists(fileloc)) { using (fs = new FileStream(fileloc,FileMode.OpenOrCreate,FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fileloc)) { sw.Write(New_Desc); } } } } I got this exception in stream writer:
The process cannot access the file '..............\Pro\Content\News\AllNews\Par.txt' because it is being used by another process. Text file is created, but I can't write to it.
Источник: https://stackoverflow.com/questions/204 ... ng-c-sharp
I try to create a text file and write some data to it. I am using the following code:
public void AddNews(string path,string News_Title,string New_Desc) { FileStream fs = null; string fileloc = path + News_Title+".txt"; if (!File.Exists(fileloc)) { using (fs = new FileStream(fileloc,FileMode.OpenOrCreate,FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fileloc)) { sw.Write(New_Desc); } } } } I got this exception in stream writer:
The process cannot access the file '..............\Pro\Content\News\AllNews\Par.txt' because it is being used by another process. Text file is created, but I can't write to it.
Источник: https://stackoverflow.com/questions/204 ... ng-c-sharp
Мобильная версия