I am using windows service to import data from excel to a database. after importing I want to move that file to backup folder.
private void moveFileToBackUpFolder(string filename, string _inputFilePath)
{
try
{
WriteToFile("moveFileToBackUpFolder " + filename);
string sourcePath = _inputFilePath;
string targetPath = _inputFilePath + "\\Backup Files";
string sourceFile = Path.Combine(sourcePath, filename);
string destFile = Path.Combine(targetPath, filename);
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
File.Move(sourceFile, destFile);
}
catch (Exception ex)
{
WriteToFile("moveFileToBackUpFolder execption " + ex.Message);
}
}
but i am getting access to the path is denied. Same code i am using in windows form and it is working. I am using windows server 2016 .
Can anyone help me tosolve this issue.
Please check which user is running the windows service ? Go to Services > Properties (Your service) > Log On
. Does that user have access to the path ?
Add the user which has access and you should be good.
Check that directory or file has proper permission. Below given reason stop to move file from one location to another.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.