protected void UploadButton_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { try { if (ddlSection.SelectedIndex != -1) { DulyDBDataContext dc = new DulyDBDataContext(); //get the extension string extension = System.IO.Path.GetExtension(FileUpload1.FileName); //generate RandomName string random = randomName(); string newFileName = random + extension; FileUpload1.SaveAs(HttpContext.Current.Server.MapPath("~") + "/Uploads/" + newFileName); //THIS IS WHERE THE PREVIEW IMG IS CREATED //open the document PdfManager objPdf = new PdfManager(); PdfDocument objDoc = objPdf.OpenDocument(HttpContext.Current.Server.MapPath("~") + "/Uploads/" + newFileName); //get the first page PdfPage firstPage = objDoc.Pages[1]; //convert to img PdfPreview objPreview = firstPage.ToImage("ResolutionX=100; ResolutionY=100"); //save objPreview.Save(HttpContext.Current.Server.MapPath("~") + "/Preview/" + random + ".png", true); //END OF PREVIEW //test link hyperlink.NavigateUrl = "http://dulynoted-001-site1.smarterasp.net/Uploads/" + newFileName; hyperlink.Visible = true; var newNote = new Note { sId = int.Parse(ddlSection.SelectedValue), userId = int.Parse(Session["dulyNoted"].ToString()), numberTimesFlagged = 0, upVoteCounter = 0, downVoteCounter = 0, source = "http://dulynoted-001-site1.smarterasp.net/Uploads/" + newFileName, preview = "http://dulynoted-001-site1.smarterasp.net/Preview/" + random + ".png", title = NoteTitle.Text, description = NoteDescription.Text, noteDate = Calendar_NoteDate.SelectedDate, uploadDate = DateTime.Now }; dc.Notes.InsertOnSubmit(newNote); dc.SubmitChanges(); //AFTER THE FILE IS UPLOADED HERE NoteTitle.Text = ""; NoteDescription.Text = ""; } else { UploadLabel1.Text = "You must select a section."; } } catch (Exception ex) { UploadLabel1.Text = "ERROR: " + ex.Message.ToString(); } } else { UploadLabel1.Text = "You have not specified a file."; } }