I have used infomentums activefile in the past with classic asp. They have version 2.5 available but i can’t download it from their website and i am afraid of downloading it from third parties like cnet etc due to exes having infections. Looking for recommendations for a good component, if it can help with file upload with status message, that would be great.
I have written my own and it is downloading the file but the file is coming up as garbage. Windows is asking me for the program to open it.
FileSystem fso = new FileSystem();
byte[] fileBytes = fso.GetFileBytes(filePath);
if (fileBytes != null)
{
result = new FileContentResult(fileBytes, "application/octet-stream");
}
This worked like a charm, thanks for your help imaginekitty.
result = new FileContentResult(fileBytes, "application/octet-stream") { FileDownloadName = fileName };
I have experimented with below code but would still prefer to use the above code. Followed a tutorial which i am not able to find again (making sure that i don’t get credit for this code).
Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
namespace Core.MvcBase
{
//download file
public class BinaryContentResult : ActionResult
{
#region CONSTANTS
public const string ApplicationOctetStream = "application/octet-stream";
#endregion
public BinaryContentResult()
{ }
public string ContentType { get; set; }
public string FileName { get; set; }
public byte[] FileBytes { get; set; }
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ClearContent();
context.HttpContext.Response.ContentType = ContentType;
context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
context.HttpContext.Response.BinaryWrite(FileBytes);
context.HttpContext.Response.End();
}
}
}
use
result = new BinaryContentResult(){
FileBytes = fileBytes,
ContentType = BinaryContentResult.ApplicationOctetStream,
FileName = fileName
};
Need an advice, is there a better approach available than first converting the file into byte array? In our case, we need to impersonate first before we get access to the file.
These files are sitting on the file server. Anonymous users can’t get to these files. No virtual paths are specified so that is not available in this case also. It’s a security measure…