protected void btn_download_Click(object sender, EventArgs e) { if (SucCookie.Exists("username")) { try { id = SucCookie.Read("fileid"); FilePath = db.GetList(string.Format("SELECT FILEPATH FROM SUC_FILES WHERE ID={0}", id))[0]; Name = db.GetList(string.Format("SELECT NAME FROM SUC_FILES WHERE ID={0}", id))[0]; string fileName = Name + FilePath.Substring(FilePath.LastIndexOf('.')); //客户端保存的文件名 string filePath = Server.MapPath(FilePath); //路径 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } catch (Exception ex) { JsUtil.ShowMsg("文件保存出错,请联系网站管理员!"); } } else { JsUtil.ShowMsg("您尚未登陆,请先登录然后才能下载!", "UserLogin.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!SucCookie.Exists("username")) { JsUtil.ShowMsg("登录已过时,请重新登录!", "Login.aspx"); } GetFunction(); }
protected void btn_upload_Click(object sender, EventArgs e) { if (file_open.HasFile) { try { if (file_open.FileContent.Length > 0) { string filename = file_open.FileName; string ext = System.IO.Path.GetExtension(filename); DateTime dt = DateTime.Now; string newname = dt.ToString("yyyyMMddHHmmssffff") + ext; string path = "~/Files/" + newname; file_open.SaveAs(System.Web.HttpContext.Current.Server.MapPath(path)); string usern = SucCookie.Read("username"); if (!string.IsNullOrEmpty(usern)) { DataTable userDT = db.GetDataTable(string.Format(@"SELECT * FROM SUC_USER WHERE LOGIN_NAME='{0}'", usern)); if (userDT.Rows.Count > 0) { DateTime publicdate = DateTime.Now; string type = sComb.Value; string fromwhere = userDT.Rows[0]["Unit"].ToString(); string userid = userDT.Rows[0]["ID"].ToString(); string filesize = (file_open.PostedFile.ContentLength / 1000).ToString() + "kb"; string filepath = path; string gradeclass = sTree.Value; db.ExecuteNonQuery(string.Format(@"INSERT INTO SUC_FILES (NAME, USER_ID,BROWNUM,TYPE,FROMWHERE,DOWNLOADNUM,FILETYPE,FILEPATH,FILESIZE,GRADE_CLASS,PUBLISH_DATE) VALUES ('" + tname.Text + "','" + userid + "','0','" + ext + "','" + fromwhere + "','0','" + type + "','" + filepath + "','" + filesize + "','" + gradeclass + "',GETDATE())")); JsUtil.ShowMsg("上传成功!", "../FP/FileUpload.aspx");//Default return; } else { JsUtil.ShowMsg("该用户不存在!"); return; } } else { JsUtil.ShowMsg("请重新登录!"); return; } } else { JsUtil.ShowMsg("请选择要上传的文件!"); return; } } catch (Exception ex) { //JsUtil.ShowMsg("上传失败,请重新上传!"); return; } } JsUtil.ShowMsg(" 您还没有选择文件或您选择的文件大小为0,请先选择文件!"); }
protected void lk_loginstate_Click(object sender, EventArgs e) { string UserN = SucCookie.Read("username"); if (!string.IsNullOrEmpty(UserN)) { JsUtil.ShowMsg("您已经成功登录!"); return; } Response.Redirect("UserLogin.aspx"); }
protected void btn_upload_Click(object sender, EventArgs e) { //file_open.SaveAs("/Video/Files/"+file_open.FileName); if (file_open.HasFile) { try { string filename = Path.GetFileName(file_open.FileName); string filetype = filename.Substring(filename.LastIndexOf(".")); file_open.SaveAs(Server.MapPath("~/css/") + filename); //保存到数据库 JsUtil.ShowMsg("上传文件成功!", "FilePage.aspx"); } catch (Exception ex) { JsUtil.ShowMsg("上传失败,请重新上传!", "FileUpload.aspx"); } } string t = ""; }