Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
im making a antivirus and with real time scanning a dialog shows when a virus is found but when i click quarantine its suppost to move the file to a folder ect but

System.IO.File.Move(Label1.Text, Application.StartupPath & "\Quarantine\")

isnt working and the directory does exist btw nothing happens to the file.can anyone help me out? thanks in advance

What I have tried:

System.IO.File.Move(Label1.Text, Application.StartupPath & "\Quarantine\")
Posted
Updated 20-Aug-17 1:05am
Comments
Thomas Daniels 20-Aug-17 6:52am    
What do you mean by "isn't working"? Does it give an error? Or does it just not move the file? And does the file in Label1.Text exist?
Helpmecodeplz 20-Aug-17 7:00am    
yeah it does exist and no i doesnt give an error i just doent move the file do you know how i could solve this or a diffent method. thanks

1 solution

When you move a file, you need to specify a whole destination file name, not just a folder.
For example:
File.Move(label1.Text, Path.Combine(quarantinePath, Path.GetFileName(label1.Text)))
Always use Path.Combine instead of concatenation - it sorts out trailing backslashes for you.

But ... the reason I used "quarantinePath" as a variable instead of Application.StartUpPath is because you shouldn't try to write to the App program folder - in production that will be below the "Program Files" which is read only without Admin permissions. In an antivirus app, that is especially important, as you would be moving dangerous files into an area that Windows expects to find executable files in...

Instead of that, use a "sensible" folder, or which there are quite a few. This may help: Where should I store my data?[^] - the code is all C#, but it's all very basic stuff.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900