protected void rep_ItemCommand(object source, RepeaterCommandEventArgs e) { string aa = e.CommandName; string id = e.CommandArgument.ToString(); if (e.CommandName == "Delete") { try { TNNEWSVIDEOInfo model = bllTNNEWSVIDEO.GetModelByID(id); string path = Server.MapPath(model.CN_VIDEO_PATH); File.Delete(path); bllTNNEWSVIDEO.Delete(id); this.BindList(); } catch (Exception ex) { LogHelper.WriteErrorLog("删除视频出错:" + ex); MessageBox.Show(this, "删除视频出错"); } } }
protected void btnUpload_Click(object sender, EventArgs e) { try { string newsId = Request.QueryString["NewsID"]; if (newsId == null) { MessageBox.Show(this, "没有对应的公司动态,无法上传视频"); return; } string fileExtension = Path.GetExtension(btnSelectFile.FileName).ToLower(); string loginId = Session["LoginID"].ToString(); string changeFileName = DateTime.Now.Ticks.ToString() + fileExtension; string filePath = Server.MapPath("/upload/video/") + changeFileName; string fileUrl = "/upload/video/" + changeFileName; if (!Directory.Exists(Server.MapPath("/upload/video/"))) { Directory.CreateDirectory(Server.MapPath("/upload/video/")); } btnSelectFile.SaveAs(filePath); TNNEWSVIDEOInfo newsVideo = new TNNEWSVIDEOInfo(); newsVideo.CN_ID = Guid.NewGuid().ToString(); newsVideo.CN_NAME = btnSelectFile.FileName; newsVideo.CR_NEWS_ID = newsId; newsVideo.CN_VIDEO_PATH = fileUrl; newsVideo.CR_CREATE_USER_ID = loginId; newsVideo.CN_CREATE_DATE = DateTime.Now; bllTNNEWSVIDEO.Add(newsVideo); BindList(); MessageBox.Show(this, "上传成功"); } catch (Exception ex) { MessageBox.Show(this, "导入报错" + ex.Message); } }