Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. if (FileUpload1.HasFile)
  2.  
  3. protected void UploadButton_Click(object sender, EventArgs e)
  4. {
  5. string saveDir = @"~Visual Studio 2015ProjectsEMPMISPASSPORTS";
  6.  
  7. string MainPath = Request.PhysicalApplicationPath;
  8.  
  9. string EMPLOYEEID = TXTEMPID.Text;
  10. string UserFile = FileUpload1.FileName;
  11.  
  12. if (FileUpload1.HasFile)
  13. {
  14. string savePath = MainPath + EMPLOYEEID + Server.HtmlEncode(UserFile);
  15.  
  16. // Append the name of the file to upload to the path.
  17. //string EMPLOYEEID = TXTEMPID.Text;
  18. // savePath += fileName + EMPLOYEEID;
  19.  
  20. FileUpload1.SaveAs(savePath);
  21.  
  22. UploadStatusLabel.Text = "Your file was saved as " + UserFile;
  23. }
  24. else
  25. {
  26. UploadStatusLabel.Text = "You did not specify a file to upload.";
  27. }
  28. }
  29.  
  30. <asp:Label ID="lblmsg" runat="server" Style="color: black; font-weight: bold; font-size: large;"
  31. Text="Image Uploaded." />
  32. <asp:FileUpload ID="fupidproof" runat="server" />
  33. <asp:HiddenField ID="hdidproof" runat="server" />
  34. <asp:Button ID="btnidproof" runat="server" Text="Upload" Style="background-color: darkcyan;
  35. color: white;" OnClick="btnidproof_Click" />
  36.  
  37. --------------------------------aspx.cs code---------------------
  38. protected void btnidproof_Click(object sender, EventArgs e)
  39. {
  40. string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
  41. SqlConnection con = new SqlConnection(str);
  42. cmd.CommandType = CommandType.StoredProcedure;
  43. SqlCommand cmd = new SqlCommand("ProcedureName", con);
  44.  
  45. string logopath = "";
  46. if (fupidproof.HasFile)
  47. {
  48. logopath = "~//Kycimg//" + Guid.NewGuid() + fupidproof.FileName;
  49. hdidproof.Value = logopath.ToString();
  50. fupidproof.SaveAs(Server.MapPath(logopath));
  51. }
  52. cmd.Parameters.AddWithValue("@Image", hdidproof.Value, SqlDbType.VarChar);
  53. cmd.ExecuteNonQuery();
  54. lblMessage.Text = "Image has been Uploaded Successfully";
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement