hi how I can convert below code to C# asp.net?
string downloadtoken = Page.RouteData.Values["downloadtoken"].ToString();
DownloadsDbEntities db = new DownloadsDbEntities();
var data = from d in db.Downloads
where d.DownloadToken == downloadtoken
select d;
Download obj = data.SingleOrDefault();
if (obj.ExpireAfterDownload.Value)
{
if (obj.Downloaded.Value)
{
Response.Redirect("~/DownloadError.aspx");
}
}
else
{
if (obj.ExpiryDate.Value < DateTime.Now)
{
Response.Redirect("~/DownloadError.aspx");
}
}
string path = Server.MapPath(obj.Url);
FileStream fs = File.OpenRead(path);
byte[] fileData = new byte[fs.Length];
fs.Read(fileData, 0, (int)fs.Length);
Response.Clear();
Response.AddHeader("Content-Type", "application/zip");
Response.AddHeader("Content-Disposition", "inline;filename=" + Path.GetFileName(path));
Response.BinaryWrite(fileData);
Response.Flush();
Response.Close();
if (obj.ExpireAfterDownload.Value)
{
obj.Downloaded = true;
obj.Hits = obj.Hits + 1;
db.SaveChanges();
}
best regards neda