Click here to Skip to main content
15,900,723 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have files for download on my website. I believe it is ASP.NET 4.5. I would like to log each file download with the file name, user name, and date. The download is initiated with a link that is displayed via code in a placeholder control. I don't know how to trigger generating a file entry when the link is clicked. Below is the code used to generate the links.
C#
	 For Each file As String In IO.Directory.GetFiles(Server.MapPath(strDir))
		lblDownloads.Visible = True
		If Not (IO.Path.GetFileName(file).EndsWith(".aspx")) Then
			Dim lnk As New HyperLink
			PlaceHolder1.Controls.Add(GetLiteral("<br>"))
			lnk.ID = "lnk" & i.ToString()
			lnk.NavigateUrl = strDir & IO.Path.GetFileName(file)
			lnk.Text = Mid(IO.Path.GetFileName(file), 1, (IO.Path.GetFileName(file)).IndexOf("."))
			' MsgBox(lnk.Text)
			If (lnk.Text = "Downloads") Then
				GoTo bypass
			End If
			If (lnk.Text = "Web") Then
				GoTo bypass
			End If
			PlaceHolder1.Controls.Add(lnk)
		End If
bypass:
		i += 1
		'End If
	Next
End Sub

Private Function GetLiteral(ByVal text As String) As Literal
	Dim rv As Literal
	rv = New Literal
	rv.Text = text
	Return rv
End Function


What I have tried:

I have searched without success.
Posted
Updated 13-Mar-24 11:57am
v3
Comments
OriginalGriff 13-Mar-24 2:04am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.

What you are asking for here only partially works if you require the user to sign up for the ability to download from your website. Even then, you are going to have to refine your requirements more as there are assumptions in there such as, do you count a partial download as a download or does the download only get counted if the user successfully completes it? Are you tracking discrete downloads or rolling them together per user?
 
Share this answer
 
As is stated here[^] you have several ways to achieve that.

I'd suggest to read this also: File Download in ASP.NET and Tracking the Status of Success/Failure of Download[^]
 
Share this answer
 
Comments
BobbyStrain 14-Mar-24 21:12pm    
Thank you. In my searching I learned that the Hyperlink control does not have a click event whereby some code can be called. So I am changing the control to Linkbutton so I can trigger code execution.
BobbyStrain 16-Mar-24 18:55pm    
Well, I successfully implemented logging using the LinkButton control. Thank you for your help.
Maciej Los 17-Mar-24 6:04am    
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900