public async Task<string> GetFilesAsync()
{
/// when bytearray need to be write to localfile
//string localfileName = "C:\\logs\\Report.pptx";
//File.WriteAllBytes(localfileName, byteArray);
/// when read file and convert to memory stream
MemoryStream ms = new MemoryStream();
string localfileName = "C:\\logs\\Report.pptx";
using (FileStream file = new FileStream(localfileName, FileMode.Open, FileAccess.Read))
{
file.CopyTo(ms);
}
await _azureRepository.SaveFileAsync(ms, "Report_.pptx");
var result = await _azureRepository.GetFileAsync("Report_.pptx");
/// when on click file need to be downloaded
if (result != null)
{
string fileName = "Report_" + DateTime.Now.ToString("ddmmyyyyhhmmss") + ".pptx";
HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", fileName));
result.WriteTo(context.Response.OutputStream);
result.Close();
context.Response.End();
return fileName + "downloaded for ";
}
return "No File";
}
No comments:
Post a Comment