????????? ????? ?? ???-?????????? ASP.NET.

??????? ????? ? ???????

???-?????????? ?????? ????????? ???? ? ?????? ???-???????. ????? ????????? ?????? ??????, ???????????? ?? ???????, ?? ?????? ????? ????. ???????????? ?????? ???????? ?????? ???????????? ??????. ???? ?????? ???? ??? ????????? ????????????? ? ???, ??? ?? ?????????.

?????????? ???-?????????? ASP.NET

????????? Visual Studio, ???????? ??????? ???-?????????? ASP.NET. ????? ??? ????? ??????? ???-?????????? ? Razor Pages. ????????? ????????? ??????? NuGet, ?? ????????? ? ???? ?????? ??? ??????: Aspose.Zip ??? ?????? ? Aspose.BarCode ??? ???????? ???????? ??????.
??????? ???????? Index.cshtml ? ???????????? ???????. ?????? ???????? ?? ??? ???????? ????? ? ??????? ???????? ?????? ???. ???????????? ?????? ??? ???????????? ?????? ?? ????????.
???????? ?? ??? ???????? ????????? HTML-????????:

1<form method="post">    
2    <input type="submit" value="Download" />
3</form>

??????????? ??????? ???????

??? ????? ??????? ?? ??????? ??? ??????? ???????, ??????? ???????????? Aspose.ZIP: ZIP, Bzip2, 7z. ????????? ???????????? ??? ??? ????????, ??????? ???????? ??? ???????? ? ??????? DisplayAttribute.
??? ???????????? ????? ?????????:

 1  ????????????? ???????????? ArchiveFormat
 2  {
 3      [????????(???="ZIP")]
 4      ???,
 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    ????????????? (?????? ??????)
 6    {
 7      ???? ArchiveFormat.Zip:
 8        ...
 9        ??????? ????? FileStreamResult (?????????, ??????????/zip) {FileDownloadName = barcode.zip};
10      ???? ArchiveFormat.Bzip2:
11        ...
12        ??????? ????? FileStreamResult (?????????, application/x-bzip2) {FileDownloadName = barcode.bmp.bz2};
13      ???? ArchiveFormat.SevenZip:
14        ...
15        ??????? ????? FileStreamResult (?????????, ??????????/x-7z-??????) {FileDownloadName = barcode.7z};                           
16    }
17  }

????? ???????, ??? ???????????? ???? ?????? ?? ?????? ??????????? ??????????????? ????? ?? ??????? ?????? (?????????? result) ? ???????? ? ??????? Microsoft.AspNetCore.Mvc.FileStreamResult, ???????? ?????????? ??? MIME.

???????? ?????????? ??????

?? ?????????? ?????????? Aspose.BarCode ??? ???????? BMP-??????????? ?????-???? ? ??????? ???? ??????????. ???????? ????????? ?????? ??????:

 1  ??????? ????? GenerateBarcode()
 2  {
 3    ????????? ??? = ????? 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          ????????? ??? = ????? MemoryStream();
 6          ????????????? (?????? ??????)
 7          {
 8              ???? ArchiveFormat.Zip:
 9                  ????????? (????? a = ????? ?????())
10                  {
11                      a.CreateEntry("barcode.bmp", ?????-???);
12                      ?.????????? (?????????);
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  }

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.