PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/getPhoto.aspx.cs

https://github.com/sirivedula/BEST
C# | 65 lines | 59 code | 6 blank | 0 comment | 6 complexity | 9190fd708e07c810a311cca37ac0b269 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using BaliEnterpriseSystems.BestObjects;
  8. using System.Data.OleDb;
  9. namespace BaliEnterpriseSystems
  10. {
  11. public partial class getPhoto : System.Web.UI.Page
  12. {
  13. protected void Page_LoadComplete(object sender, EventArgs e)
  14. {
  15. Response.Cache.SetCacheability(HttpCacheability.NoCache);
  16. if (HttpContext.Current.Session["CurrentUser"] == null)
  17. {
  18. Response.Redirect("Logout.aspx");
  19. }
  20. var ePhoto = new BestStudentPicture();
  21. OleDbCommand myCmd = ePhoto.dbCmd;
  22. myCmd.CommandText = "select photosize, photoname, picture from beststudentpicture where centerid = ? and studentid = ?";
  23. OleDbParameter sid = new OleDbParameter("studentid",OleDbType.VarChar, 50);
  24. sid.Value = Request.QueryString["sid"];
  25. OleDbParameter cid = new OleDbParameter("centerid", OleDbType.VarChar, 50);
  26. cid.Value = Request.QueryString["cid"];
  27. myCmd.Parameters.Add(cid);
  28. myCmd.Parameters.Add(sid);
  29. OleDbDataReader readphoto = myCmd.ExecuteReader();
  30. bool hasPhoto = false;
  31. if(readphoto.Read())
  32. {
  33. if (readphoto.GetValue(1).GetType() != Type.GetType("System.DBNull"))
  34. {
  35. string photoname = readphoto.GetString(1);
  36. var tvalue = readphoto.GetValue(2);
  37. photo = (byte[])tvalue;
  38. Response.AddHeader("content-disposition", "inline;filename=" + Server.UrlEncode(photoname));
  39. Response.ContentType = "images/" + (System.IO.Path.GetExtension(photoname) ?? "jpg").ToLower();
  40. Response.BinaryWrite(photo);
  41. hasPhoto = true;
  42. }
  43. }
  44. if(! hasPhoto)
  45. {
  46. Response.AddHeader("content-disposition", "inline;filename=PhotoDoesNotExist.png");
  47. Response.ContentType = "image/png";
  48. Response.WriteFile(Server.MapPath("images/NoPhotoYet.png"));
  49. Response.End();
  50. return;
  51. }
  52. }
  53. private byte[] photo
  54. {
  55. get;
  56. set;
  57. }
  58. }
  59. }