protected void loadLinkButton_Click(object sender, EventArgs e) { var photoId = int.Parse(loadPhotoIdTextBox.Text); var photoDescription = PhotoData.SelectPhotoDescription(photoId); photoImage.ImageUrl = string.Format("/PhotoHandler.ashx?photoId={0}", photoId); photoDescriptionLabel.Text = photoDescription; }
protected void saveLinkButton_Click(object sender, EventArgs e) { if (!photoFileUpload.HasFile) { return; } var photoId = int.Parse(savePhotoIdTextBox.Text); var desc = descriptionTextBox.Text; var httpStream = photoFileUpload.FileContent; PhotoData.InsertPhoto(photoId, desc, httpStream); }
public void ProcessRequest(HttpContext context) { if (!int.TryParse(context.Request.QueryString["photoId"], out int photoId)) { return; } byte[] bytes = PhotoData.SelectPhotoImage(photoId); context.Response.ContentType = MediaTypeNames.Image.Jpeg; context.Response.BufferOutput = false; context.Response.AddHeader("content-length", bytes.Length.ToString()); // not necessary, but nice to let the client know using (MemoryStream ms = new MemoryStream(bytes)) { ms.CopyTo(context.Response.OutputStream); } }