本文整理匯總了C#中System.IO.FileInfo.Decrypt方法的典型用法代碼示例。如果您正苦於以下問題:C# FileInfo.Decrypt方法的具體用法?C# FileInfo.Decrypt怎麽用?C# FileInfo.Decrypt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.Decrypt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string FileName = @"c:\MyTest.txt";
Console.WriteLine("Encrypt " + FileName);
// Encrypt the file.
AddEncryption(FileName);
Console.WriteLine("Decrypt " + FileName);
// Decrypt the file.
RemoveEncryption(FileName);
Console.WriteLine("Done");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public static void AddEncryption(string FileName)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
if (!fInfo.Exists)
{
//Create the file.
fInfo.Create();
}
// Add encryption.
fInfo.Encrypt();
}
public static void RemoveEncryption(string FileName)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
if (!fInfo.Exists)
{
//Create the file.
fInfo.Create();
}
// Remove encryption.
fInfo.Decrypt();
}
}
}
//This code produces output similar to the following;
//results may vary based on the computer/file structure/etc.:
//
//Encrypt c:\MyTest.txt
//Decrypt c:\MyTest.txt
//Done