???????? ?????????? ? ????????? .docx Word

????????

?? ?????? ??????? ??? ?????????? ???-???????? ASP.NET ??? ????????? ???? ????????? ?? ????????? ??????? Microsoft Docx.

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

?????????????? Visual Studio, ???????? ?????? ???-???????? ASP.NET Core ?? ?????????? Razor. ?????????????? ????????? ??????? NuGet, ??????????? ??? ??????? ??? ????? ???????: Aspose.Zip ??? ??????????? ?? Aspose.Imaging ??? ????????? ??????????.
???????? ???????? Index.cshtml ? ?????? Solution Explorer. ????? ??????? ????? ?? ???? ???????? ? ????????? enctype="multipart/form-data" ? ???? <form>. ???????? ???? ????????? ???????? Word ?? ???-??????. ????? ??????? ???? ???????? ???? file ??? ????????????? ????? docx. ??? ????? ???????? HTML ??? ?????:

1<form method="post" enctype="multipart/form-data">
2    <span>Microsoft *.docx document: </span>
3    <input type="file" name="uploadedFile" required="required" accept=".docx" />   
4    <br />
5    <input type="submit" value="Upload" />
6</form>

??? ????????? ??????????? ?????? ???????? �????????�.

????????? Docx

Docx documet ??? ?? ???? ? zip-???????. ???? ??? ??? ????-??? ????????? ??????????, ???? ??????????? ? ????? �word/media� ????? ?????????. ????, ?????????? ????? ???? docx ? ???????? ?????. ?? ??????? ??????? ??? ???????? ???????? ??????????? ????? OnPost ??? ??????? Index.cshtml.cs. ? ????? ?????? ?? ????????? ????? zip ?? ????????? ???????????? ????????????. ??? ???????? ??????:

 1    public void OnPost(IFormFile uploadedFile) {
 2        using (Archive archive = new Archive(uploadedFile.OpenReadStream())) {
 3            using (Archive archive = new Archive(uploadedFile.OpenReadStream()))
 4            {
 5                foreach (var entry in archive.Entries.Where(e => e.Name.StartsWith(@"word/media", StringComparison.InvariantCultureIgnoreCase)))
 6                {
 7                ...
 8                }
 9            }	
10        }
11    }

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

????? ????????? ??? ???????? ??????????, ?? ?????????? ????? ????????? ? ???????????. ??? ????? ?? ?????? ??????????????? ????? Image.CanLoad. ???? ???? ?????????? ?????? ??????????, ??? ???????? ???????? ???? ????? ? ?????? ????????, ??? ??????????? ?? ??????????. ??????? ??????????? public List<byte[]> ImageBytes { get; ????????? ?????; } ?? IndexModel. ?? ?????????? ??? ?????? ??????????? ??????? ?????????. ??? ???????? ?? ?? ???-????????, ?? ?????????????? data URI ?? ????????????? ?????? ?????????? ?? ????? base64. ??? ??? ???????????? Razor ?? Index.cshtml

1    @{
2    if (Model.ImageBytes != null && Model.ImageBytes.Count > 0) {
3            <h4>Images within document:</h4>
4            foreach (byte[] image in Model.ImageBytes) {
5                <img src="data:image;base64,@Convert.ToBase64String(image)"/>
6            }
7        }
8    }

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

????, ?�??????? ??? ?????. ????? ????? ?????? ???? ???????????, ? ????? ?? ??? ?????? ???? ???????? ??????????.
?? ?? ??????????? ???? ??????????? ? ????? ??????. ? ???????? ????????? ??? ???? ?????????? ???????????? ????? ? ???? ?????.
????? ???????? ???????? ????? OnPost.

 1public void OnPost(IFormFile uploadedFile)
 2{
 3    ImageBytes = ????? ??????<byte[]>();
 4
 5    using (Archive archive = new Archive(uploadedFile.OpenReadStream()))
 6    {
 7        foreach (var entry in archive.Entries.Where(e => e.Name.StartsWith(@"word/media", StringComparison.InvariantCultureIgnoreCase)))
 8        {
 9            using (MemoryStream extracted = new MemoryStream())
10            {
11                entry.Open().CopyTo(extracted);
12                extracted.Seek(0, SeekOrigin.Begin);
13
14                if (Aspose.Imaging.Image.CanLoad(extracted))
15                    ImageBytes.Add(extracted.ToArray());
16             }
17         }
18     }
19}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.