Well, I don't know how to type all this so bear with me please.
This is beyond me, I'm still a newb at C#. I basically need to create a folder in the roaming application data of the current user running the program. I also need to access another folder in the application data section and then replace a file with a copy of the file in the application data folder I had created.
Select File Explorer Options. Select the View tab of the File Explorer Options window. Choose Show hidden files, folders, and drives > Apply > OK. The AppData folder is located at C:\users\YOURNAME, where YOURNAME is your Windows profile ID.
Double-click AppData in the 1 and 2 directories and change the path to the folder directory you want to transfer in the pop-up box. Then copy all the data in the original AppData directory to whichever directory you modified, and finally restart your computer.
Normally, you will not find the AppData folder in your User Profile page because it is hidden by default. We will change the hidden settings and then access the file location. Make sure that you are logged in as an administrator.
You want to delete the contents of AppData folder. The AppData folder would have data regarding the applications in the computer. If its contents are deleted, data would be lost and you may not be able to use some applications as well.
The first two passes are straightforward
// The folder for the roaming current user
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
// Combine the base folder with your specific folder....
string specificFolder = Path.Combine(folder, "YourSpecificFolder");
// CreateDirectory will check if every folder in path exists and, if not, create them.
// If all folders exist then CreateDirectory will do nothing.
Directory.CreateDirectory(specificFolder);
In the last pass is not clear where you have the file to copy.
However, supposing that you have a file called
string file = @"C:\program files\myapp\file.txt";
File.Copy(file, Path.Combine(specificFolder, Path.GetFileName(file));
MSDN links:
Path class
Environment.SpecialFolder enum
File.Copy method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With