change my upload system with c# -
i want make code upload in .docx or .pdf im confuse, how can change code ? im can upload when data image
there code in aspx.cs
protected void save_click(object sender, eventargs e) { //upload photo int h, w; string folder = "photo/"; h = 298; w = 765; string asl = uploadincresize(h, w, folder, upload, false); string insert = "insert pm_formkl(title, proponent, assessor, score, upload) " + "values('" + cf.strsql(title.text) + "','" + cf.strsql(proponent.text) + "','" + cf.strsql(assessor.text) + "','" + cf.strsql(score.text) + "','" + asl + "')"; db.execute(insert); response.redirect("/detail penilaian/kl/formkl.aspx"); } // upload image protected string uploadfile(string folder, fileupload img) { string upload_file = ""; try { string filename = path.getfilename(img.filename); string dir = param.pathimage + folder; bool status = true; while (status) { status = fileexists(filename, server.mappath("~/images/" + folder)); if (status) filename = getrandomfilename() + system.io.path.getextension(img.postedfile.filename); } //teaser_image.saveas(server.mappath("~/images/") + folder + filename); upload_file = filename; string large = dir + filename; img.postedfile.saveas(large); } catch (exception ex) { js.alert(this, "upload status: file not uploaded. following error occured: " + ex.message); } return upload_file; } protected string uploadincresize(int h, int w, string folder, fileupload img, bool resize) { string upload_file = ""; try { if (img.postedfile.contenttype == "image/jpeg" || img.postedfile.contenttype == "image/png" || img.postedfile.contenttype == "image/gif") { string filename = path.getfilename(img.filename); string dir = param.pathimage + folder; bool status = true; while (status) { status = fileexists(filename, server.mappath("~/images/" + folder)); if (status) filename = getrandomfilename() + system.io.path.getextension(img.postedfile.filename); } upload_file = filename; string temp = dir + "(kl)" + filename; string large = dir + filename; img.postedfile.saveas(temp); if (resize) { imgh.crop(temp, large, h, w); } else { img.postedfile.saveas(large); } file.delete(temp); js.alert(this, "upload status: upload successfull."); } else js.alert(this, "upload status: jpeg , png or gif files allowed!"); } catch (exception ex) { js.alert(this, "upload status: file not uploaded. following error occured: " + ex.message); } return upload_file; } protected string getrandomfilename() { random rand = new random((int)datetime.now.ticks); int newfile = 0; newfile = rand.next(1, 9999999); return newfile.tostring(); } protected bool fileexists(string filename, string path) { fileinfo imagefile = new fileinfo(path + filename); bool filestatus = imagefile.exists; return filestatus; }
Comments
Post a Comment