This project is a Windows console application that manages files by integrating MS SQL Server and the local file system. It compares the file list in the database with local files, moves files not present in the database to a temporary folder, and automatically deletes files that have passed a certain period. 한국어 버전(Korean Version)
- Connect to MS SQL Server and query the database
- Query a view containing file names
- Retrieve file list from a specific local folder
- Move files not in the database to a temp folder
- Record file name and move date in a DB temp table
- Query files in the temp table that have passed a certain period (default 30 days)
- Delete those files from the temp folder and remove records from the DB temp table
- Encrypt connection strings in the App.config for security
- Windows OS
- .NET Framework 4.8
- MS SQL Server
- Appropriate file system permissions
The solution consists of the following files:
- FileManagerApp.cs: Main program logic
- App.config: Application configuration file
- ConfigEncryption.cs: App.config encryption utility
- ConfigEncryptionProgram.cs: Config file encryption management tool
- CustomEncryption.cs: Custom encryption implementation
- ConnectionStringManager.cs: Connection string management class
- Build the project.
- Set SQL server connection info and file paths in App.config:
<connectionStrings>
<add name="SqlConnection" connectionString="Data Source=YOUR_SERVER;Initial Catalog=YOUR_DATABASE;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="SourceFolderPath" value="C:\SourceFiles" />
<add key="TempFolderPath" value="C:\TempFiles" />
<add key="FileViewName" value="vwValidFiles" />
<add key="TempTableName" value="TempMovedFiles" />
<add key="DaysToKeep" value="30" />
</appSettings>- Ensure the required view exists in the database.
- The view must have a "FileName" column.
- (If needed) Run ConfigEncryptionProgram to encrypt the connection string.
FileManagerApp.exe
The program performs the following steps in order:
- Create temp table if it does not exist
- Query file list from DB
- Query file list from local folder
- Move files not in DB to temp folder and record in DB
- Delete temp files older than specified days and remove records from DB
ConfigEncryptionProgram.exe
Select the desired encryption/decryption operation from the menu:
- Encrypt ConnectionStrings section
- Decrypt ConnectionStrings section
- Encrypt AppSettings section
- Decrypt AppSettings section
This project provides three types of encryption:
- Section-level encryption (ConfigEncryption.cs)
- Uses Windows DPAPI to encrypt entire sections of App.config.
- Tied to user or machine account.
- Managed via
ConfigEncryptionProgram.exe.
- Custom encryption (CustomEncryption.cs)
- Custom AES-based encryption implementation.
- Key can be managed via file, allowing server migration.
- Programmatic control over encryption/decryption.
- Password-only encryption (ConnectionStringManager.cs)
- Encrypts only the password part of the connection string.
- Maintains config readability while enhancing security.
- Supports automatic decryption at runtime.
- Windows DPAPI can only be decrypted by the same account.
- Custom encryption keys should be managed securely.
- Do not use hardcoded keys in production; use an external key management system.
- Choose the appropriate encryption method for service accounts.
This project is provided under the MIT License.