An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hi @MIPAKTEH_1 , Welcome to Microsoft Q&A,
You cannot enforce restrictions at the OS level directly from your application.
If your application allows saving files, you can restrict it to a specific directory.
string sourceDir = @"C:\Users\sy\Documents\";
SaveFileDialog saveDialog = new SaveFileDialog
{
InitialDirectory = sourceDir,
Filter = "All Files|*.*",
RestoreDirectory = true
};
if (saveDialog.ShowDialog() == DialogResult.OK)
{
string savePath = saveDialog.FileName;
if (!savePath.StartsWith(sourceDir, StringComparison.OrdinalIgnoreCase))
{
MessageBox.Show("You can only save files to the designated directory.");
return;
}
// Save file logic
File.WriteAllText(savePath, "Your file content here");
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.