I’m trying to create a document and send it to the browser in asp .net core v5. I’ve got this working in .net 4.8. I am upgrading my app to .net core 5.
I’ve tried to call the same method like this which is what I did in .NET 4.8
doc.Save(Response, “QRCode.doc”, ContentDisposition.Inline, null);
I don’t see any good way to stream the document down to the browser in asp .net core. What am I missing? The error I get is a compile error saying
Severity Code Description Project File Line Suppression State
Error CS1501 No overload for method ‘Save’ takes 4 arguments
@wallym Aspose.Words for .NET Standard does not have this overload of Save method. Please see the article for more information.
In Razor you should use MVC controller to sent file to the client’s browser. In your Setup.Configure method add the following line
app.UseMvcWithDefaultRoute();
Create controller that generates file and returns FileContentResult. See the example below:
using Aspose.Words;
using Microsoft.AspNetCore.Mvc;
using System.IO;
namespace TestAspNetCoreApp.Controllers
{
public class AWController : Controller
{
public FileResult SaveFile()
{
// Create a simple document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Write some text in the document.
builder.Writeln("Hello Aspose.Words!");
// Write OS we are running on.
builder.Writeln("You are running on " + System.Environment.OSVersion.VersionString);
// Insert some image into the document.
builder.InsertImage(@"https://cms.admin.containerize.com/templates/aspose/App_Themes/V3/images/aspose-logo.png");
// Now save the created document to PDF and return as a FileContentResult.
using (MemoryStream ms = new MemoryStream())
{
doc.Save(ms, SaveFormat.Pdf);
return File(ms.ToArray(), "application/pdf", "out.pdf");
}
}
}
}
On your page create a link or button, for example:
@Html.ActionLink("Generate Document using Aspose.Words", "SaveFile", "AW")