How can O make a simple file download counter with ASP.NET in C# ? For example when a user clicked and download file i wanna update it with +1 and save it's filename to DB. when user onmouse over link i wanna shows a tooltip with File Downloaded Times.But If user Cancel downloading status it wont update it .
A:
If you don't want to update unless the file is completely downloaded, you'll have to write your own generic handler, in which you update the database at the very end of processing.
For the DB, I'd recommend having one table where you store each download occurrence, and one where you store information about each file, for example
tblDownloads
************
DlID (GUID, not nullable, primary key)
Date (datetime, not nullable)
FileID (GUID, not nullable)
tblFiles
********
FileID (GUID, not nullable, primary key)
Url (nvarchar(255), not nullable)
Title (nvarchar(255), not nullable)
Description (nvarchar(max))
(Example datatypes etc are named as they would be in MSSQL...)
To get the download count of a specific file, you then simply query the database for
SELECT COUNT(DlID) FROM tblDownloads WHERE FileID = @FileID
where @FileID
is a parameter with the file ID you're interested in. If you want to loop out urls for all files, you could for example query
SELECT
f.FileID, f.Url, f.Title, f.Description, COUNT(d.DlID) AS DownloadCount
FROM tblFiles f INNER JOIN tblDownloads d ON f.FileID = d.FileID
GROUP BY f.FileID, f.Url, f.Title, f.Description
Tomas Lycken
2009-05-24 10:50:08
so can ya gimme example for generic handle for this?
Ibrahim AKGUN
2009-05-24 15:10:15
I've updated the post.
Tomas Lycken
2009-05-24 19:35:22
And I would appreciate if the user that voted me down would give me a hint on why... =)
Tomas Lycken
2009-05-24 20:07:56
You need to tell the man why he is wrong otherwise how will he correct himself?
Andrei Rinea
2009-05-24 22:19:22