Move Report Files
Automating Report Management in Wise SCADA: Secure File Relocation Using C# Scripts
In Wise SCADA, the report module saves generated reports into a specific folder named exactly after the defined report symbol within the project directory. While this structure is internal to the system, allowing users to access the project folder directly to retrieve these reports is not ideal for system security and integrity.
To maintain a secure environment, we can use a C# script to automatically move these reports from the internal project folders to a designated external directory.
Why Use a Script to Move Reports?
- Security: Users do not need access to sensitive project files or SCADA configurations.
- Organization: Reports can be moved to a shared network drive or a dedicated “User Reports” folder.
- Automation: By running this script in the Setup section on a time-based trigger, the process becomes completely hands-off.
The Logic: Secure and Silent Execution
The following script identifies files in the source report directory and attempts to move them to a target directory. If a file is currently open or being written to by the SCADA system, the File.Move command will throw an exception. However, our script handles this “silently”—it ignores the error for now and simply attempts to move that specific file again during the next scheduled cycle.
The C# Script
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.CSharp;
public class MainClass
{
public void Main()
{
MoveFiles(@"C:\Wise SCADA Proje\Report\MyReport_1", @"C:\Wise SCADA Proje\Report\MyReport_1B");
MoveFiles(@"C:\Wise SCADA Proje\Report\MyReport_2", @"C:\Wise SCADA Proje\Report\MyReport_2B");
}
private void MoveFiles(string Source, string Target){
try
{
if (!Directory.Exists(Source)){
MessageBox.Show("Source not valid!");
}
if (!Directory.Exists(Target)){
Directory.CreateDirectory(Target);
}
string[] Files = Directory.GetFiles(Source);
foreach (string FilePath in Files)
{
string FileName = Path.GetFileName(FilePath);
string NewPath = Path.Combine(Target, FileName);
File.Move(FilePath, NewPath);
//File.Copy(FilePath, NewPath);
//File.Delete(FilePath);
}
}
catch (Exception ex)
{
//MessageBox.Show("File move error: " + ex.Message);
}
}
}
Key Implementation Details
- Scheduled Execution: We recommend running this script in the Setup section of Wise SCADA with a time-based script (e.g., every 1 minute or every hour).
- Conflict Handling: By leaving the catch block empty (or using it for internal logging), we ensure that an “Access Denied” error caused by an open report doesn’t interrupt the SCADA runtime or bother the user with pop-ups.
- Target Directory Safety: The script automatically checks for the existence of the target folder and creates it if necessary, ensuring the operation never fails due to a missing path.
By implementing this simple automation, you keep your Wise SCADA project environment secure while making report access seamless for your clients.
