hi this is Table Download in database
Id
DownLoadTitle
Url
DownloadToken
ExpiryDate
Hits
ExpireAfterDownload
Downloaded
and below is code that connect to this database
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();
}
but in above code I don't know how it call table from database I never seen this kind of code it doesn't connect to database
can you please help me I want above code but connect to sql and read table Download from database in sql server
How I can do it?
Best regards
Neda