Telerik RadFileExplorer 和服务器端代码
我有一个如下所示的文件浏览器:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchBar.aspx.cs" Inherits="FileExplorer.SearchBar" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
// function OnClientFileOpen(oExplorer, args) {
// args.set_cancel(true);
// radopen(args.get_item().get_url());
// }
function OnClientFileOpen(oExplorer, args) {
var item = args.get_item();
var fileExtension = item.get_extension();
var fileDownloadMode = document.getElementById("chkbxDownoaldFile").checked;
if ((fileDownloadMode == true) && (fileExtension == "jpg" || fileExtension == "gif")) {// Download the file
// File is a image document, do not open a new window
args.set_cancel(true);
// Tell browser to open file directly
var requestImage = "Handler.ashx?path=" + item.get_url();
document.location = requestImage;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" Height="400px" Hidth="600px"
EnableCreateNewFolder="false" EnableCopy="true" OnClientFileOpen="OnClientFileOpen" enableopenfile="true">
<Configuration ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
</telerik:RadFileExplorer>
<br />
<asp:CheckBox ID="chkbxDownoaldFile" runat="server" Text="Open images for direct download " />
</div>
</form>
</body>
</html>
上面的代码只是一个示例,您可以在下面的链接中看到他们的演示...
FileExplorer / 过滤文件并下载
我想要允许我的用户从我的服务器下载任何文件,无需任何预览(只需另存为窗口)...
因此,为了这个目的,我可以轻松地更改上面的代码。
但这里有一种情况->我想捕获和过滤下载(文件大小限制)(sql server 2008 数据库)。
看来 RadFileExplorer 仅具有用于我目的的客户端事件!
当我的页面加载时,我想向我的用户显示 RadFileExplorer,以便在没有任何下载权限的情况下查看它的文件。
当他/她双击文件时,我告诉该用户请先登录!
登录后,他/她可以下载文件,但每天只能下载 1 GB。 我怎样才能为我的 RadFileExplorer 做这些事情?
对于这种情况,Web 服务和 Web 方法是一个好主意吗?
提前致谢
i have a file explorer like below :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchBar.aspx.cs" Inherits="FileExplorer.SearchBar" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
// function OnClientFileOpen(oExplorer, args) {
// args.set_cancel(true);
// radopen(args.get_item().get_url());
// }
function OnClientFileOpen(oExplorer, args) {
var item = args.get_item();
var fileExtension = item.get_extension();
var fileDownloadMode = document.getElementById("chkbxDownoaldFile").checked;
if ((fileDownloadMode == true) && (fileExtension == "jpg" || fileExtension == "gif")) {// Download the file
// File is a image document, do not open a new window
args.set_cancel(true);
// Tell browser to open file directly
var requestImage = "Handler.ashx?path=" + item.get_url();
document.location = requestImage;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" Height="400px" Hidth="600px"
EnableCreateNewFolder="false" EnableCopy="true" OnClientFileOpen="OnClientFileOpen" enableopenfile="true">
<Configuration ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
</telerik:RadFileExplorer>
<br />
<asp:CheckBox ID="chkbxDownoaldFile" runat="server" Text="Open images for direct download " />
</div>
</form>
</body>
</html>
the upper codes are just an example and you can see their demo in the below link ...
FileExplorer / Filter files and download
i want to allow my users to download any file from my server without any preview (just save as window)...
so for this purpose i can change the upper codes easily.
but there is a situation here -> i want to capture and filter downloads (file size limit) (sql server 2008 database).
it seems RadFileExplorer only has client side events for my purpose!
when my page loads , i want to show RadFileExplorer to my user for just seeing it's files without any permission for download.
when he/she double clicks on a file i tell that user plz login first!
after his/her logined , he/she can download files but only 1 GB per day.
how can i do this stuff for my RadFileExplorer ?
is web service and web methodes a good idea for this situation?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的代码依赖于处理程序 - “Handler.ashx”。所有文件都使用此处理程序进行流式传输,因此您可以在其代码中实现服务器端限制。我认为如果用户未登录,您还可以使用处理程序将浏览器重定向到不同的页面。
The code you are using relies on a handler - "Handler.ashx". All files are streamed using this handler so you can implement your server side restrictions in its code. I think you can also use the handler to redirect the browser to a different page if the user is not logged in.