I am trying to write a service which builds an .ics calendar file from string (which works) and send it to front-end. Front-end gets that file as a result of an api query. This is how it looks on my side:
var dataBytes = Encoding.ASCII.GetBytes(icsString);
var dataStream = new MemoryStream(dataBytes);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(dataStream) };
httpResponseMessage.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = "file.ics" };
httpResponseMessage.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
return httpResponseMessage;
Is it correct? If it should work, then how to get the data in JS on the front-end side?