实例介绍
【实例简介】
创建无限级文件夹,上传文件,可进行删除,下载
分享等功能,异步上传
无限级文件夹:可在根目录中创建文件夹,点击文件夹即可进入下一级目录,可上传文件或新建目录
下载:单击列表中的文件即可下载文件
分享:用户分享文件链接会生成提取码,其它用户进入该链接需输入提取码比对,正确的进入下载,错误的提取码不允许下载
会员分为普通会员与VIP超级会员。会员通过VIP激活码可以升级成为VIP超级会员
普通会员最多允许上传100MB大小的文件
VIP超级会员允许10g大小的文件
注意该系统只支持windows系统安装,带安装文档
安装sql server2008r2或以上版本数据库
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Food
{
public partial class LookFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Request["InfoID"] != null&&Request["type"]==null)
{
HiddenField1.Value = " and ParentInfoID = " int.Parse(Request["InfoID"].ToString()) " ";
}
else
{
if (Request["type"] == null)
{
HiddenField1.Value = " and ParentInfoID = 0 ";
}
}
if (Request["type"] == null)
{
Repeater1.DataSource = DBUtility.DbHelperSQL.Query("select * from WP_Class where UserInfoID = '" Session["LoginInfoID"].ToString() "' " HiddenField1.Value).Tables[0];
Repeater1.DataBind();
}
else
{
if (Request["type"].ToString() == "pic")
{
HiddenField1.Value = " and (OldName like '%.png%' or OldName like '%.jpeg%' or OldName like '%.jpg%')";
}
if (Request["type"].ToString() == "video")
{
HiddenField1.Value = " and (OldName like '%.mp4%' or OldName like '%.flv%' or OldName like '%.mpeg%')";
}
if (Request["type"].ToString() == "music")
{
HiddenField1.Value = " and (OldName like '%.mp3%' )";
}
if (Request["type"].ToString() == "torrent")
{
HiddenField1.Value = " and (OldName like '%.torrent%' )";
}
if (Request["type"].ToString() == "word")
{
HiddenField1.Value = " and (OldName like '%.txt%' or OldName like '%.doc%' or OldName like '%.xls%' or OldName like '%.pdf%' or OldName like '%.xlxs%')";
}
if (Request["type"].ToString() == "other")
{
HiddenField1.Value = " and OldName not like '%.jpeg%' and OldName not like '%.png%' and OldName not like '%.jpg%' and OldName not like '%.torrent%' and OldName not like '%.mp3%' and OldName not like '%.mp4%' and OldName not like '%.flv%' and OldName not like '%.mpeg%' and OldName not like '%.txt%' and OldName not like '%.doc%' and OldName not like '%.xls%' and OldName not like '%.pdf%' and OldName not like '%.xlxs%' ";
}
}
Repeater2.DataSource = DBUtility.DbHelperSQL.Query("select * from WP_File where UserInfoID = '" Session["LoginInfoID"].ToString() "' " HiddenField1.Value).Tables[0];
Repeater2.DataBind();
Literal1.Text = (Repeater1.Items.Count Repeater2.Items.Count).ToString();
object allcount = DBUtility.DbHelperSQL.GetSingle("select sum(cast(filelength as bigint)) from WP_File where UserInfoID = '" Session["LoginInfoID"].ToString() "'");
if (allcount == null) { HiddenField3.Value = "0"; }
else { HiddenField3.Value = allcount.ToString(); }
HiddenField4.Value = Session["UserLevel"].ToString();
}
}
public string ShowClass(string filename)
{
if (filename.ToLower().IndexOf(".zip") > 0 || filename.ToLower().IndexOf(".rar") > 0 || filename.ToLower().IndexOf(".7z") > 0)
{
return "fileicon-small-zip";
}
else if (filename.ToLower().IndexOf(".jpeg") > 0 || filename.ToLower().IndexOf(".jpg") > 0 || filename.ToLower().IndexOf(".png") > 0)
{
return "fileicon-small-pic";
}
else
{
return "default-small";
}
}
public string JS(string filelength)
{
double dsj = (double.Parse(filelength) / double.Parse("1024"));
int sj = int.Parse(Math.Ceiling(dsj).ToString());
if (sj.ToString().Length <= 3) { return dsj.ToString("0.00") "KB"; }
else
{
double dsj1=(double.Parse(sj.ToString()) / double.Parse("1024"));
int sj1 = int.Parse(Math.Ceiling(dsj1).ToString());
if (sj1.ToString().Length <= 3) { return dsj1.ToString("0.00") "MB"; }
else
{
double dsj2 = (double.Parse(sj.ToString()) / (double.Parse("1024") * double.Parse("1024")));
int sj2 = int.Parse(Math.Ceiling(dsj2).ToString());
return dsj2.ToString("0.00") "G";
}
}
}
public int ShowID(object rid)
{
if (rid != null) { return int.Parse(rid.ToString()); }
else { return 0; }
}
protected void Button2_Click(object sender, EventArgs e)
{
new BLL.GZXX_Model().DeleteContent("WP_File", int.Parse(HiddenField2.Value));
if (Request["InfoID"] == null)
{
if (Request["type"] == null)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), System.DateTime.Now.Ticks.ToString(), "layer.alert('删除成功!', {icon: 1,kin: 'layer-ext-moon',closeBtn: 0 }, function () { location.href='LookFile.aspx';})", true);
}
else
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), System.DateTime.Now.Ticks.ToString(), "layer.alert('删除成功!', {icon: 1,kin: 'layer-ext-moon',closeBtn: 0 }, function () { location.href='LookFile.aspx?type=" Request["type"].ToString() "';})", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), System.DateTime.Now.Ticks.ToString(), "layer.alert('删除成功!', {icon: 1,kin: 'layer-ext-moon',closeBtn: 0 }, function () { location.href='LookFile.aspx?InfoID=" Request["InfoID"].ToString() "';})", true);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sFileName = Server.MapPath(HiddenField2.Value);
FileStream fileStream = new FileStream(sFileName, FileMode.Open);
long fileSize = fileStream.Length;
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
//如果不写fileStream.Close()语句,用户在下载过程中选择取消,将不能再次下载
fileStream.Close();
Context.Response.ContentType = "application/octet-stream";
Context.Response.AppendHeader("Content-Disposition", "attachment;filename=" HttpUtility.UrlEncode(sFileName, Encoding.UTF8));
Context.Response.AddHeader("Content-Length", fileSize.ToString());
Context.Response.BinaryWrite(fileBuffer);
Context.Response.End();
Context.Response.Close();
}
}
}
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论