C# - ASP NET - How to fix error - The process cannot access the file because it is being used

preview_player
Показать описание

Additional information: The process cannot access the file because it is being used by another process.

Рекомендации по теме
Комментарии
Автор

This worked for me, The basic concept is once u create a file ensure that u close the file before u write anything to it. Once writing is done again close the file.

ProperComment
Автор

I don't have any stream to close.. What would i do? here is my code
private void MoveFiles()
{
string openFile = Environment.CurrentDirectory;
string sourcePath = @"F:\EStatementFiles";
string targetPath = @"F:\EStatementFilesOld";

if
{

}

string[] sourceFiles =

foreach (string sourceFile in sourcefiles)
{
string fileName = Path.GetFileName(sourceFile);
string destFile = Path.Combine(targetPath, fileName);

File.Move(sourceFile, destFile);
}

}

kaysernayem