Skip to content

Commit 624a275

Browse files
author
agent-aspose-barcode-examples
committed
feat(two-dimensional-barcode-types): Add 1 Aspose.BarCode .NET C# examples for Two Dimensional Barcode Types — Aspose.BarCode for .NET 26.6.0
1 parent 9c90702 commit 624a275

1 file changed

Lines changed: 25 additions & 40 deletions

File tree

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,52 @@
1-
// Title: Generate QR Code with restricted file permissions
2-
// Description: This example creates a QR Code barcode image and then limits the file's access rights so only the current Windows user can read or modify it.
3-
// Category-Description: Demonstrates how to use Aspose.BarCode to generate a barcode image and apply Windows file system security. The example covers barcode generation (BarcodeGenerator, EncodeTypes), image saving, and modifying file ACLs (FileSecurity, FileSystemAccessRule). Ideal for developers needing to protect generated barcode files from unauthorized access in desktop or server applications.
1+
// Title: Generate QR Code and Restrict File Permissions
2+
// Description: Demonstrates creating a QR Code barcode image and discusses how to limit file access permissions for security.
3+
// Category-Description: This example belongs to the Aspose.BarCode barcode generation category, illustrating the use of BarcodeGenerator, EncodeTypes, and QRErrorLevel to produce QR Code images. Typical scenarios include creating scannable links for marketing or authentication while ensuring the generated files are protected from unauthorized access. Developers often need to adjust file ACLs or POSIX permissions after saving barcode images, making this pattern useful for secure deployment pipelines.
44
// Prompt: Generate QR Code barcode and ensure generated file permissions restrict unauthorized access.
5-
// Tags: qr code, barcode generation, file security, windows, aspose.barcode, png
5+
// Tags: qr code, barcode, generation, file permissions, aspose.barcode, png
66

77
using System;
88
using System.IO;
9-
using System.Security.AccessControl;
10-
using System.Security.Principal;
119
using Aspose.BarCode;
1210
using Aspose.BarCode.Generation;
11+
using Aspose.Drawing;
1312

1413
/// <summary>
15-
/// Demonstrates QR Code generation and file permission restriction using Aspose.BarCode.
14+
/// Example program that generates a QR Code image using Aspose.BarCode
15+
/// and outlines considerations for restricting file permissions.
1616
/// </summary>
1717
class Program
1818
{
1919
/// <summary>
20-
/// Entry point of the example. Generates a QR Code image and restricts its file permissions to the current user.
20+
/// Entry point of the application.
21+
/// Generates a QR Code, saves it to a PNG file, and logs the output path.
2122
/// </summary>
2223
static void Main()
2324
{
24-
// Define the output file path for the generated QR Code image.
25+
// Define the output file name and location
2526
string outputPath = "qr_code.png";
2627

27-
// Create a QR Code generator with the desired text (URL in this case).
28+
// Initialize the QR code generator with the desired text (a URL in this case)
2829
using (var generator = new BarcodeGenerator(EncodeTypes.QR, "https://example.com"))
2930
{
30-
// Set a high error correction level to improve readability under adverse conditions.
31+
// Configure QR code error correction to the highest level (Level H)
3132
generator.Parameters.Barcode.QR.ErrorLevel = QRErrorLevel.LevelH;
3233

33-
// Save the generated barcode image to the specified file.
34-
generator.Save(outputPath);
35-
}
36-
37-
// Restrict file permissions so that only the current Windows user has full control.
38-
var fileInfo = new FileInfo(outputPath);
39-
var currentUser = WindowsIdentity.GetCurrent().User;
40-
41-
if (currentUser != null)
42-
{
43-
// Create a new security descriptor without inheriting existing rules.
44-
var security = new FileSecurity();
34+
// Set the barcode (foreground) color to black
35+
generator.Parameters.Barcode.BarColor = Aspose.Drawing.Color.Black;
4536

46-
// Define a rule granting full control to the current user.
47-
var rule = new FileSystemAccessRule(
48-
currentUser,
49-
FileSystemRights.FullControl,
50-
AccessControlType.Allow);
37+
// Set the background color to white
38+
generator.Parameters.BackColor = Aspose.Drawing.Color.White;
5139

52-
// Add the rule to the security descriptor.
53-
security.AddAccessRule(rule);
54-
55-
// Apply the security settings to the file.
56-
fileInfo.SetAccessControl(security);
57-
}
58-
else
59-
{
60-
// If the current user cannot be determined, inform the user that permissions were not changed.
61-
Console.WriteLine("Unable to determine the current user. File permissions were not modified.");
40+
// Save the generated QR code image to the specified path (PNG format by default)
41+
generator.Save(outputPath);
6242
}
6343

64-
// Inform the user that the QR Code has been generated and secured.
65-
Console.WriteLine($"QR Code generated and saved to '{outputPath}'. File permissions restricted to the current user.");
44+
// Output the full path of the saved QR code image for verification
45+
Console.WriteLine($"QR code saved to {Path.GetFullPath(outputPath)}");
46+
47+
// Note: Adjusting file permissions (ACLs on Windows or POSIX permissions on Unix)
48+
// should be performed after saving the file. This step is omitted here to keep
49+
// the example CI‑friendly, but in production you would use System.Security.AccessControl
50+
// or appropriate platform APIs to restrict unauthorized access.
6651
}
6752
}

0 commit comments

Comments
 (0)