简单的网络硬盘

 
简单的网络硬盘
qq群:19877329
By: jfan 2007-07-19
 
本人正在开发协同办公系统( oa ),在里面有资料管理模块。呵呵,说明白点就是让用户能在指定的地方新建文件夹、上传文件、删除文件、删除文件夹等一些权限的设计嘛!
想了想,要求如下:
1.        文件夹间的跳转:进入下一级,返回上一级。
2.        上传文件到指定文件夹。
3.        下载文件到本机或在线查看文件内容。
4.        删除文件或文件夹。
5.        修改查看文件的权限。
6.        修改操作文件的权限(主要是删除权限、下载)。
开发环境: window xp,ms sql 2000,vs 2005.
思路:
权限设计时,如果没个文件的权限都不同,好像有点不现在,也没这个必要。所以呢,我就只设文件夹的权限,(呵呵,偷懒而起)但是根目录(在我这是 update 目录)是所有人都有查看的权限,至于修改的就不能给了。
说这么多,还是先看看运行效果(嘿嘿,没一点效果谁理你啊,再写多也是女人的裹脚布)
(首页是这样,至于那几按钮的权限就分到了系统权限来实现!)
各个说明下:
1.        上传文件呢,是用户可把文件上传到当前文件夹下。
2.        新建文件夹,指用户在当前目录下建文件夹。
不知道发现没?如果不这样,就有漏洞了。
3.        权限分成了:修改权限(其实起操作权限更适合、查看权限)
(这就是修改权限了,在目录里你可选要修改的目录,第一个 listbox 里是显示了所有用户的姓名,把要给权限的用户加到第二 listbox 里点 确定 ’,OK ! 但这我偷了懒,没把已有权限的用户读出来,呵,不能怪我,只能怪这时间安排的太紧)
4.        上传文件我是用了第三方控件,叫什么名字?呃 …. 我看看。打不到了,只有它类名: Webb.WAVE.Controls.Upload 呵,这控件还行,看demo时,那多文件上传看来要改改。有时间我也来做个demo吧。
注:上传文件时一定要注意是否有重名。因为上传时我没有重命名。
5.        下面的就是新建文件夹了。
考考大家,如果文件夹名有空格等一些乱七八糟的字符时,怎么处理。呵呵。
 
代码:
还是看看代码吧!
下面就是读取文件夹名、文件名等的代码,我也不想多说,看不懂就算了,呵。也不是很难。
这代码写得很糟糕,就不想修改,唉,算了,还是抛砖吧!
public partial class docManage_index : System.Web.UI.Page
{
AdoNetCon anc = new AdoNetCon(ConfigurationManager.AppSettings["ZWOAConnectionString"]);
// 我的一个小小类,用来操作数据库
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Write(Server.MapPath("update"));
        GridView1.DataSource = bind(Server.MapPath("update"));
        GridView1.DataBind();
    }
  
  //把读取的文件夹名,文件名,操作等一些东东放到datatable里。用gridview显示
    public DataTable bind(string fullFolderPath)
    {
        if ((Request.QueryString["path"] != null) && (Request.QueryString["path"] != "") && (Request.QueryString["path"] != "update"))
// 判断要打开的路径
        {
            if (!isEnter(Request.QueryString["path"]))
            {
                //Response.Write(Request.QueryString["path"]);
                Response.Write(" 你的权限不够!" );
                Response.End();
            }
        }
        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add(new DataColumn("type", System.Type.GetType("System.String")));// 类型
        dt.Columns.Add(new DataColumn("name", System.Type.GetType("System.String")));// 名称
        dt.Columns.Add(new DataColumn("action", System.Type.GetType("System.String")));// 操作
        dt.Columns.Add(new DataColumn("delete", System.Type.GetType("System.String")));// 删除
        if ((Request.QueryString["path"] != null) && (Request.QueryString["path"] != "update"))
        {
            int h = fullFolderPath.LastIndexOf("update");
            fullFolderPath = fullFolderPath.Substring(0, h);
            fullFolderPath = fullFolderPath + "//" + Request.QueryString["path"];
            int g = fullFolderPath.LastIndexOf("update");
            string temp = fullFolderPath.Substring(g);
            int l = temp.LastIndexOf("//");
            temp = temp.Substring(0, l);
            Label2.Text = fullFolderPath.Substring(g);
            Label3.Text = "<a href=index.aspx?path=" + temp + "> 上级</a>" ;
        }
        else
        {
            Label2.Text = "update";
        }
    
        foreach (string d in Directory.GetFileSystemEntries(fullFolderPath))
        {
            dr = dt.NewRow();// 建新行
            int i = d.LastIndexOf("//");
            string txt = d.Substring(i+1);
            dr[1] = txt;// 名称name
            if (File.Exists(d))// 如果是文件
            {
                dr[0] = " 文件" ;// 类型type
                int pos = fullFolderPath.IndexOf("update");
                string relaUrl = fullFolderPath.Substring(pos);
                string url =serverUrl() +"//"+ relaUrl +"//"+ txt;// 服务器地址,你应该将它修改为你所在服务器地址
                url = url.Replace(" ", "%20");
               dr[2] = "<a href= " + url + "> 下载</a>" ;
                //dr[2] ="<a href="+url;
                //Response.Write(url);
                //Response.Write(dr[2].ToString());
                dr[3] = fullFolderPath +"//"+ txt;
            }
            else if (Directory.Exists(d))
            {
                int j = d.LastIndexOf("update");
                string dir = d.Substring(j);
                dr[0] = " 文件夹" ;//type 类型
                    if (isEnter(dir))
                    {
                        dir = dir.Replace(" ", "%20");
                        //Response.Write(dir);
                        dr[2] = "<a href=index.aspx?path="+HttpUtility.HtmlEncode(dir)+"> 进入</a>" ;// 操作action
                        dir = dir.Replace("%20", " ");
                        //Response.Write(dir);
                    }
                    if (isMod(dir))
                    {
                        dir = dir.Replace(" ", "%20");
                        dr[3] = fullFolderPath + "//"+txt;
                        dr[2] = dr[2] + " " + "<a href=modfiy.aspx?sonPath=" +HttpUtility.HtmlEncode(dir) + "> 属性</a>" ;
                    }
            }
            else
            {
                Response.Write("<script>alert(' 无对象可绑定!')</script>" );
            }
            dt.Rows.Add(dr);// 添加行
        }
        return dt;
    }
  
  //是否有权限进入
    public bool isEnter(string directory)
    {
        bool falg = false;
        try
        {
            string root_id = anc.ReturnValue("select top 1 root_id from tb_docRoot where root_path = " +"'"+ directory + "'");
            falg = anc.ExistDate("select root_id from tb_docRight where root_id="
                           + "'" + root_id + "'"
                           + " and user_id=1"
                           + " and root_in=1" );
            // 我操作数据库的一方法,有权限就返回true,不然就是false
        }
        catch(Exception ex)
        {
            Response.Write(" 错误" + ex.Message);
        }
        return falg;
    }
 
    // 判断是否有修改的权限
    public bool isMod(string directory)
    {
        bool falg = false;
        try
        {
           string root_id = anc.ReturnValue("select top 1 root_id from tb_docRoot where root_path = " + "'"+ directory + "'");
           falg = anc.ExistDate("select root_id from tb_docRight where root_id="
                           + "'" + root_id + "'"
                           + " and user_id=" + "'1'"
                           + " and root_del=1");
        }
        catch (Exception ex)
        {
            Response.Write(" 错误" + ex.Message);
        }
        return falg;
    }
 
  //得到服务器的地址
    public string serverUrl()
    {
        string serverName = Request.ServerVariables["Server_Name"];
        string url = Request.ServerVariables["Url"];
        int j = url.LastIndexOf("/");
        url = url.Substring(0,j);
        return "http://" + serverName + url;
    }
 
    // 删除文件夹,文件
    public void DeleteFolder(string dir)
    {
        if (File.Exists(dir))
        {
            File.Delete(dir);
        }
        else
        {
            {
                foreach (string d in Directory.GetFileSystemEntries(dir))
                {
                    if (File.Exists(d))
                        File.Delete(d);// 直接删除其中的文件
                    else
                        DeleteFolder(d);// 递归删除子文件夹
                }
                Directory.Delete(dir);// 删除已空文件夹
            }
        }
    }
 
    public void delete(Object sender, CommandEventArgs e)
    {
        DeleteFolder(e.CommandArgument.ToString());
        try
        {
            //Response.Write(e.CommandArgument.ToString());
            int pos = e.CommandArgument.ToString().IndexOf("update");
            string path = e.CommandArgument.ToString().Substring(pos);
            //Response.Write(path);
            string root_id = anc.ReturnValue("select top 1 root_id from tb_docRoot where root_path = " + "'" + path + "'");
            anc.RunProc("delete tb_docRoot where root_path="+ "'" + path+ "'");
            anc.RunProc("delete tb_docRight where root_id = " + "'" + root_id + "'");
        }
        catch (Exception ex)
        {
            Response.Write(" 错误" + ex.Message);
        }
        GridView1.DataSource = bind(Server.MapPath("update"));
        GridView1.DataBind();
}
 
 
    protected void addDirBtn_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["path"] == null)
        {
            Response.Redirect("addDir.aspx?pPath=" + Server.MapPath("update"));
        }
        else
        {
            Response.Redirect("addDir.aspx?pPath=" + Server.UrlEncode(Server.MapPath(".") + "//" + Request.QueryString["path"].ToString()));
 
        }
    }
    protected void updateBtn_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["path"] == null)
        {
            Response.Redirect("update.aspx?uPath=" + HttpUtility.HtmlEncode(Server.MapPath("update")));
        }
        else
        {
            Response.Redirect("update.aspx?uPath=" + Server.UrlEncode(Server.MapPath(".") + "//" + Request.QueryString["path"].ToString()));
        }
    }
    protected void lookBtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("lookRight.aspx");
    }
    protected void modBtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("modRight.aspx");
    }
}
 
就这些代码吧,其它的都简单,没有必要写出来现丑了。OK,OVER.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值