.docx Word ???? ??? ??
??
? ????? Microsoft Docx ?? ???? ?? ???? ???? ?? ASP.NET ? ?? ????? ???? ??? ?????.
ASP.NET ? ?????? ??
Visual Studio? ???? Razor Pages? ?? ??? ASP.NET Core ? ??????? ?????.
NuGet ??? ???? ???? ????? ?? ? ?? ???, ? ?? ???
Aspose.Zip? ??? ???
Aspose.Imaging? ?????.
??? ????? Index.cshtml ???? ????. ?? <form> ?? ?? enctype="multipart/form-data" ??? ???? ?? ???? ??? ?????. Word ??? ? ??? ???? ????. ?? ?? ???? docx ??? ?? file ??? ?? ??? ?????.
??? ??? ?? ?? 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>??? ??? ?? Accept ??? ???????.
Docx ??
Docx documet? zip ???? ? ?????. ??? ???? ?? ?? ?? ? ‘word/media’ ??? ?????. ??? ???? docx ??? ???? ??? ?????. ?? ???? Index.cshtml.cs ??? ?? ??? OnPost ???? ???? ???. ? ?? ???
??? ???? ????
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? ?????.
? ??? ??? ??? ???? ????. ????? ???? ?? ??? ???? base64 ???? ????
??? URI? ?????.
??? Index.cshtml? ?? ??? Razor ?????.
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 = new List<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}