if you are using .Net use global.asax and use below code in your global.asax code behind file
Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
' Fires right before the request handler executes
'Files is folder in the file path
If Context.Request.Url.AbsoluteUri.IndexOf("/Files/") > 0 Then
If Context.Request.Url.AbsoluteUri.IndexOf(".doc") > 0 Then
Context.Response.End()
End If
End If
End Sub