Exemple #1
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string   courseName = ((Label)GridView1.Rows[e.RowIndex].Cells[1].FindControl("Label1")).Text.ToString();
        string   time       = ((Label)GridView1.Rows[e.RowIndex].Cells[2].FindControl("Label2")).Text.ToString();
        string   tempPath   = BusyworkManage.Path + tm.ReturnTeacherID(Request.Cookies["StudentID"].Value.ToString()) + BusyworkManage.TopicPath + courseName + "/" + courseName + "_" + time + ".doc";
        string   path       = Server.MapPath(tempPath);
        FileInfo fInfo      = new FileInfo(path);
        string   fname      = fInfo.Name;

        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fname));
        Response.AddHeader("Content-Length", fInfo.Length.ToString());
        Response.ContentType = "application/octet-stream";
        Response.WriteFile(fInfo.FullName);
        Response.Flush();
        Response.End();
    }
    public void UploadFile(string name)
    {
        string coursename    = Request.QueryString["course"].ToString() + "/";
        string path          = Server.MapPath(BusyworkManage.Path + tm.ReturnTeacherID(Request.Cookies["StudentID"].Value.ToString()) + BusyworkManage.BusyworkPath + coursename + name + ".doc");
        string fileExtension = System.IO.Path.GetExtension(FUL.PostedFile.FileName).ToLower();
        bool   result        = bm.CheckFileExtension(fileExtension);

        if (result == true)
        {
            FUL.PostedFile.SaveAs(path);
            bm.InsertBusyworkName(Request.QueryString["course"].ToString(), Request.QueryString["time"].ToString(), Request.Cookies["StudentID"].Value.ToString(), name);
            Response.Write("<Script language='JavaScript'>alert('" + "添加成功!" + "');</Script>");
        }
        else
        {
            Response.Write("<Script language='JavaScript'>alert('" + "格式不正确!" + "');</Script>");
        }
    }