?????????? ????? ?? ???-??????? ASP.NET
??????????? ????? ? ???????
???????????? ????? ? ?????? ???-??????? ? ????????? ???????? ???-???????. ??? ???????? ?????? ?????, ?? ??????????? ?? ?????, ?? ?????? ???????? ????. ????????????? ?????? ??????? ?????? ?????? ??? ????????????. ??? ??????? ??? ??? ????? ????????? ??? ??, ?? ??? ????????.
?????????? ???-??????? ASP.NET
?????????????? Visual Studio, ???????? ASP.NET Core Web Application. ????? ?? ???? ?????? ???-???????? ?? ?????????? Razor.
?? ????????? ?????????? ??????? NuGet ?? ????????? ??? ?????? ??? ????? ???????:
Aspose.Zip ??? ????????? ??
Aspose.BarCode ??? ????????? ??????? ?????.
???????? ???????? Index.cshtml ? ?????? Solution Explorer. ????? ??????? ????? ?? ???? ???????? ? ??????? ?????????? ?? ???. ???????? ???? ?????????? ????? ?? ???????????? ????????????.
??????? ?? ???? ???????? ???? ???????? HTML:
1<form method="post">
2 <input type="submit" value="Download" />
3</form>?????? ???????? ???????
??? ????? ?????? ?? ??????? ???
??????? ???????, ??? ????????? Aspose.ZIP: ZIP, Bzip2, 7z.
???????? ??????? ??? ??? ????????, ?????????? ???? ?????
DisplayAttribute
??? ???????? ???? ?????:
1 ????????? ??????? ArchiveFormat
2 {
3 [Display(Name = "ZIP")]
4 Zip,
5
6 [Display(Name = "Bzip2")]
7 Bz2,
8
9 [Display(Name = "7z")]
10 SevenZip
11 }???? ??? ???????? ???????? ??????? ?????? ? ???-?????. ? Html-??????????
GetEnumSelectList ?? ?????? ?????? � ?? ???????? ?????????? ???????? ?? ????????? ?????.
?????? ??????? ? ???? ????? ?? Index.cshtml ????????? ????????:
1<select name="archiveFormat" asp-items="Html.GetEnumSelectList<ArchiveFormat>()"></select>????????? ???????? ?? ??????????? ???????? ???????. ?? ???????? ???? ???????:
??????? ?????? ???????????
????, ?????????? ?????? ??????? ?????? ?????? ?? ???????? �???????????�. ?? ???????? ???? ????? ?? ??????? ???????? ?????????????? ?????? ASP.NET, ??? ???????? ???????? ??????????? ????? OnPost ??? ??????? Index.cshtml.cs. ??? ???????? ??????:
1
2
3 public FileStreamResult OnPost([FromForm] ArchiveFormat archiveFormat)
4 {
5 ????????? (archiveFormat)
6 {
7 case ArchiveFormat.Zip:
8 ...
9 return new FileStreamResult(result, "application/zip") {FileDownloadName = "barcode.zip"};
10 case ArchiveFormat.Bzip2:
11 ...
12 return new FileStreamResult(result, "application/x-bzip2") {FileDownloadName = "barcode.bmp.bz2"};
13 case ArchiveFormat.SevenZip:
14 ...
15 return new FileStreamResult(result, "application/x-7z-compressed") {FileDownloadName = "barcode.7z"};
16 }
17 }????, ??? ???????????? ???? ?????? ?? ??????? ??????????? ??????????? ????? ?? ????????? ????? (?????? result) ? ?????????? Microsoft.AspNetCore.Mvc.FileStreamResult, ?? ??? ?????????? ??? MIME.
????????? ?????????? ?????
?? ?????????????? ?????????? Aspose.BarCode ??? ????????? BMP-?????????? ?????-???? ?? ????????? ???? ??????????. ???????? ????????? ?????? ?????:
1 ????????? ????? GenerateBarcode()
2 {
3 var generator = new Aspose.BarCode.Generation.BarcodeGenerator(
4 Aspose.BarCode.Generation.EncodeTypes.Pdf417, "?? ????? ????????? ????. \n ?????? ????? \n ?????? ?????.");
5
6 generator.Parameters.Barcode.XDimension.Millimeters = 0.6f;
7 generator.Parameters.Barcode.BarHeight.Millimeters = 1.2f;
8
9 MemoryStream result = new MemoryStream();
10 generator.Save(result, Aspose.BarCode.Generation.BarCodeImageFormat.Bmp);
11 result.Seek(0, SeekOrigin.Begin);
12 return result;
13 }?????????? ?????????
????? ? ??? ? ????? ???????????? ????? ?? ?????? GenerateBarcode. ???????? ???? ???????? ????? ? ??????? ???????. ????? ???????? ???????? ????? OnPost.
1public FileStreamResult OnPost([FromForm] ArchiveFormat archiveFormat)
2 {
3 ?????????????? (var barcode = this.GenerateBarcode())
4 {
5 var result = new MemoryStream();
6 ????????? (archiveFormat)
7 {
8 case ArchiveFormat.Zip:
9 ?????????????? (????? a = ????? ?????())
10 {
11 a.CreateEntry("barcode.bmp", ?????-???);
12 a.Save(?????????);
13 }
14
15 result.Seek(0, SeekOrigin.Begin);
16 return new FileStreamResult(result, "application/zip") {FileDownloadName = "barcode.zip"};
17 case ArchiveFormat.Bzip2:
18 using (Bzip2Archive a = new Bzip2Archive())
19 {
20 a.SetSource(barcode);
21 a.Save(result);
22 }
23
24 result.Seek(0, SeekOrigin.Begin);
25 return new FileStreamResult(result, "application/x-bzip2") {FileDownloadName = "barcode.bmp.bz2"};
26 case ArchiveFormat.SevenZip:
27 using (SevenZipArchive a = new SevenZipArchive())
28 {
29 a.CreateEntry("barcode.bmp", barcode);
30 a.Save(result);
31 }
32
33 result.Seek(0, SeekOrigin.Begin);
34 return new FileStreamResult(result, "application/x-7z-compressed") {FileDownloadName = "barcode.7z"};
35 default:
36 throw new ArgumentOutOfRangeException(nameof(archiveFormat));
37 }
38 }
39 }