//Удаление книги из БД protected void delete_OnClick(object sender, EventArgs e) { var temp = book.Book; var deleteBook = from book1 in temp where book1.Id.ToString() == id select book1; ClassCombine combine = new ClassCombine(); try { File.Delete(combine.combine(Server.MapPath(deleteBook.FirstOrDefault().Обложка))); File.Delete(combine.combine(Server.MapPath(deleteBook.FirstOrDefault().Путь_к_Файлу))); this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script language='javascript'>alert( 'Successful File delete' );</script>"); } catch (IOException exc) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script language='javascript'>alert( 'Error File not deleted' );</script>"); } temp.RemoveRange(deleteBook); book.SaveChanges(); }
private void fileLoad(string fileFormat, string path, FileUpload fileUpload) { int fileSize = (2 * 1024 * 1024); string format = Path.GetExtension(fileUpload.PostedFile.FileName); int size = fileUpload.PostedFile.ContentLength; if (!format.Equals(fileFormat)) { error.Text = "Неподдерживаемое расширение файла"; } else { if (size > fileSize) { error.Text = "Неожиданно большой размер файла"; } else { ClassCombine combine = new ClassCombine(); path = combine.combine(Server.MapPath(path)) + fileUpload.PostedFile.FileName; fileUpload.SaveAs(path); error.Style["color"] = "yellow"; error.Text += "Файл успешно загружен: " + fileUpload.PostedFile.FileName + "</br></br>"; } } }
//Скачивание файла книги с сервера protected void load_OnClick(object sender, EventArgs e) { var temp = book.Book; string path; foreach (var g in temp) { try { if (g.Id == Convert.ToInt32(id)) { ClassCombine combine = new ClassCombine(); path = combine.combine(Server.MapPath(g.Путь_к_Файлу)); FileInfo file = new FileInfo(path); Context.Response.AddHeader("Content-Length", file.Length.ToString()); Context.Response.AddHeader("Connection", "Keep-Alive"); Context.Response.ContentType = "text/plain"; Context.Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name); Context.Response.WriteFile(file.FullName); Context.Response.End(); } } catch (FormatException) { Response.Redirect("~/Pages/WebForm1.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { string name = Request.QueryString["name"]; if (string.IsNullOrEmpty(name)) { Response.Redirect("~/Pages/HomePage.aspx"); } else { ClassCombine combine = new ClassCombine(); path = combine.combine(Server.MapPath(name)); FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read); var encod = Encoding.GetEncoding("windows-1251"); StreamReader stream = new StreamReader(file, encod); label.Text = stream.ReadToEnd(); } }