/// <summary> /// 删除资源文件 /// </summary> /// <param name="context"></param> public void DelRecources(HttpContext context) { ZwJson zwJson = new ZwJson(); ResourcesService resourcesService = new ResourcesService(session); var name = context.Request.Params["name"]; var courseid = context.Request.Params["courseid"]; var type = context.Request.Params["type"]; var pathAll = ""; switch (type) { case "课程列表": pathAll = _filepath + courseid + @"\" + name; break; case "视频列表": pathAll = _video + courseid + @"\" + name; break; case "flashPdf": pathAll = _flash + courseid + @"\" + name; break; } try { resourcesService.DeleteByName(new Resources() { Name = name, Flag = type }); zwJson.IsSuccess = true; zwJson.JsExecuteMethod = "ajax_DelRecources"; File.Delete(pathAll); context.Response.Write(_jss.Serialize(zwJson)); } catch (Exception) { throw; } }
/// <summary> /// 保存课程资源文件 /// </summary> /// <param name="context"></param> public void SaveFile(HttpContext context) { ZwJson zwJson = new ZwJson(); ResourcesService resourcesService = new ResourcesService(session); HttpPostedFile file = context.Request.Files["Filedata"]; var courseid = context.Request.Params["id"]; var type = context.Request.Params["type"]; Resources resources = new Resources(); if (file == null) return; var pathAll = ""; var httppath = ""; var pathDirectory = ""; switch (type) { case "课程列表": pathAll = _filepath + courseid + @"\" + file.FileName; httppath = "/CourseFile/" + courseid + @"\" + file.FileName; pathDirectory = _filepath + courseid; break; case "视频列表": pathAll = _video + courseid + @"\" + file.FileName; httppath = "/OlFile/" + courseid + @"\" + file.FileName; pathDirectory = _video + courseid; break; case "flashPdf": pathAll = _flash + courseid + @"\" + file.FileName; httppath = "/FlashFile/" + courseid + @"\" + file.FileName; pathDirectory = _flash + courseid; break; } var url = UrlHelper.Resolve(httppath); int size = file.ContentLength / 1024; var flag = file.ContentLength % 1024; if (flag > 0) { size++; } resources.FileSize = size.ToString(CultureInfo.InvariantCulture); resources.Flag = type; resources.Name = file.FileName; resources.FileType = file.FileName.Split('.')[file.FileName.Split('.').Length - 1]; resources.FilePath = url; resources.CreateDt = DateTime.Now; resources.Course = new Model.Course() { Id = courseid }; if (!Directory.Exists(pathDirectory)) { Directory.CreateDirectory(pathDirectory); } if (File.Exists(pathAll)) { resourcesService.DeleteByName(resources); } resources.Id = Guid.NewGuid().ToString(); resourcesService.Save(resources); file.SaveAs(pathAll); //zwJson.IsSuccess = true; //zwJson.JsExecuteMethod = "ajax_SaveFile"; //context.Response.Write(_jss.Serialize(zwJson)); }