Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //获取ID
        StrID = Convert.ToInt32(Request.QueryString["id"].ToString());
        Fannie.DownloadZone dz1 = new Fannie.DownloadZone();
        DataSet             ds1 = new DataSet();

        ds1 = dz1.Getonefile(StrID);
        DataTable dt1 = ds1.Tables[0];

        if (!IsPostBack)
        {
            txt_filetitle.Text   = dt1.Rows[0]["title"].ToString();
            txt_discription.Text = dt1.Rows[0]["describe"].ToString();
        }
    }
Exemplo n.º 2
0
    public void Dtbind()
    {
        ZoneList.DataKeyNames = new string[] { "DataNo" };
        Fannie.DownloadZone dz1 = new Fannie.DownloadZone();
        DataSet             ds1 = new DataSet();
        DataTable           dt1 = new DataTable();

        ds1 = dz1.Getfile();
        dt1 = ds1.Tables[0];
        for (int i = 0; i < dt1.Rows.Count; i++)
        {
            dt1.Rows[i]["title"]    = SubStr(Convert.ToString(dt1.Rows[i]["title"]), 40);
            dt1.Rows[i]["describe"] = SubStr(Convert.ToString(dt1.Rows[i]["describe"]), 50);
        }
        ZoneList.DataSource = dz1.Getfile();
        ZoneList.DataBind();
    }
Exemplo n.º 3
0
    protected void DownloadBtn_Click(object sender, EventArgs e)
    {
        Fannie.DownloadZone dz2 = new Fannie.DownloadZone();
        DataTable           dt2 = new DataTable();
        ImageButton         img = (ImageButton)sender;

        // LinkButton lbtn = sender as LinkButton;
        dt2 = dz2.Getonefile(Convert.ToInt32(img.CommandArgument)).Tables[0];
        if (dt2.Rows[0]["FilePath"].ToString() != "")
        {
            //if (!File.Exists(dt2.Rows[0]["FilePath"].ToString()))
            //{
            //    Response.Write("<script>alert('附件不存在!')<script>");
            //}
            //else
            //{
            //获取文件名
            string FileNameNoExtension = System.IO.Path.GetFileNameWithoutExtension(dt2.Rows[0]["FilePath"].ToString()).ToLower();
            //获取文件后缀
            string FileExtension = System.IO.Path.GetExtension(dt2.Rows[0]["FilePath"].ToString()).ToLower();
            string FileFullName  = FileNameNoExtension + FileExtension;
            string filepath      = Server.MapPath("~/") + "DownloadZone\\" + FileFullName;
            Response.Clear();
            Response.Charset     = "utf-8";
            Response.Buffer      = true;
            this.EnableViewState = false;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileFullName));
            Response.ContentType = "application/unknown";
            Response.WriteFile(filepath);
            Response.Flush();
            Response.Close();
            Response.End();
            //}
        }
        else
        {
            Response.Write("<script>alert('没有文件不存在!');window.history.back();</script>");
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// 删除所选文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        int count = 0;
        int flag  = this.ZoneList.Rows.Count;

        Fannie.DownloadZone dz2 = new Fannie.DownloadZone();
        for (int i = 0; i < flag; i++)
        {
            CheckBox cb = (CheckBox)this.ZoneList.Rows[i].FindControl("CB1");
            if (cb.Checked == true)
            {
                dz2.Deletefile(Convert.ToInt32(ZoneList.DataKeys[i].Value.ToString()));
            }
            else
            {
                count++;
            }
        }
        if (count == flag)
        {
            Response.Write("<script>alert('请先选择需要删除的记录');window.location.href='ZoneManage.aspx';</script>");
        }
        Dtbind();
    }
Exemplo n.º 5
0
    //修改文档信息
    protected void btnModify_Click1(object sender, EventArgs e)
    {
        #region 属性
        string              filetitle;
        string              filedescribe;
        string              filepath;
        DateTime            dtm        = DateTime.Now;
        string              signdate   = DateTime.Now.ToString("yyyyMMddHHmm");
        DateTime            uploadtime = dtm.ToUniversalTime();
        Fannie.DownloadZone dz2        = new Fannie.DownloadZone();
        DataSet             ds1        = new DataSet();
        ds1 = dz2.Getonefile(StrID);
        DataTable dt2 = ds1.Tables[0];
        #endregion

        if (this.FileUploadMain.Visible == true)
        {
            #region 判断控件内是否添加了文件,如添加,则判断是否属于规定类型,否则警告
            if (FileUploadMain.HasFile)
            {
                bool     fileOK            = false;
                string   fileExtension     = System.IO.Path.GetExtension(FileUploadMain.FileName).ToLower();
                String[] allowedExtensions = { ".doc", ".docx", ".xls", ".ppt", ".rar", ".zip" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
                if (fileOK == false)
                {
                    Response.Write("<script>alert('上传的附件只能是.doc、.docx、.xls、.ppt、.rar、.zip类型!请重新上传。')</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<script>alert('您还没有选择上传文件!');history.go(-1)</script>");
                return;
            }
            #endregion

            #region 判断上传的文件是否大于50MB
            if (FileUploadMain.HasFile)
            {
                int filesize = (FileUploadMain.PostedFile.ContentLength);
                if (filesize > 51200)
                {
                    Response.Write("<script>alert('您上传的文件大于50MB,请重新选择')<script>");
                    return;
                }
            }
            #endregion

            //获取文件名
            string FileNameNoExtension = System.IO.Path.GetFileNameWithoutExtension(FileUploadMain.FileName).ToLower();
            //获取文件后缀
            string FileExtension = System.IO.Path.GetExtension(FileUploadMain.FileName).ToLower();

            #region 判断服务器是否存在同名文件,如是则要求更改,否则上传成功
            filepath = Server.MapPath("~/") + "DownloadZone\\" + signdate + "-" + FileUploadMain.FileName;
            if (File.Exists(filepath))
            {
                Response.Write("<script>alert('您即将上传的文件已在专区中存在,请重新选择文件或者更改文件名')<script>");
            }
            FileUploadMain.SaveAs(filepath);
            filetitle    = txt_filetitle.Text;
            filedescribe = txt_discription.Text;
            int flag1 = dz2.Updatefile(StrID, filetitle, filedescribe, uploadtime, filepath);
            if (flag1 > 0)
            {
                Response.Write("<script language='javascript'>alert('上传文件成功!');window.location.href='ZoneManage.aspx';</script>");
            }
            else
            {
                Response.Write("<script language='javascript'>alert('上传文件失败!');window.location.href='ZoneUpload.aspx';</script>");
            }
            #endregion
        }
        else
        {
            filetitle    = txt_filetitle.Text;
            filedescribe = txt_discription.Text;
            uploadtime   = Convert.ToDateTime(dt2.Rows[0]["uploadtime"].ToString());
            filepath     = dt2.Rows[0]["filepath"].ToString();
            int flag2 = dz2.Updatefile(StrID, filetitle, filedescribe, uploadtime, filepath);
            if (flag2 > 0)
            {
                Response.Write("<script language='javascript'>alert('修改成功!');window.location.href='ZoneManage.aspx';</script>");
            }
        }
    }