private void UploadSponsorLogo(vwarDAL.IDataRepository dal, ContentObject co) { if (this.SponsorLogoRadioButtonList.SelectedItem != null) { switch (this.SponsorLogoRadioButtonList.SelectedValue.Trim()) { case "0": //use profile logo //use profile logo if use current and there's an empty file name otherwise don't change if (string.IsNullOrEmpty(co.SponsorLogoImageFileName)) { DataTable dt = UserProfileDB.GetUserProfileSponsorLogoByUserName(Context.User.Identity.Name); if (dt != null && dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; if (dr["Logo"] != System.DBNull.Value && dr["LogoContentType"] != System.DBNull.Value && !string.IsNullOrEmpty(dr["LogoContentType"].ToString())) { var data = (byte[])dr["Logo"]; using (MemoryStream s = new MemoryStream()) { s.Write(data, 0, data.Length); s.Position = 0; //filename co.SponsorLogoImageFileName = "sponsor.jpg"; if (!string.IsNullOrEmpty(dr["FileName"].ToString())) { co.SponsorLogoImageFileName = dr["FileName"].ToString(); } FedoraContentObject.SponsorLogoImageFileNameId = dal.SetContentFile(s, co, co.SponsorLogoImageFileName); } } } } break; case "1": //Upload logo if (this.SponsorLogoFileUpload.FileContent.Length > 0 && !string.IsNullOrEmpty(this.SponsorLogoFileUpload.FileName)) { co.SponsorLogoImageFileName = this.SponsorLogoFileUpload.FileName; co.DeveloperLogoImageFileNameId = dal.SetContentFile(this.SponsorLogoFileUpload.FileContent, co, this.SponsorLogoFileUpload.FileName); } break; case "2": //none break; } } }
public static void WriteContentFileToResponse(string Pid, string filename, HttpContext context, vwarDAL.IDataRepository vd) { Stream data = null;//= vd.GetContentFile(Pid, co.DisplayFileId); if (data == null) data = vd.GetContentFile(Pid, filename); context.Response.ContentType = "application/octet-stream"; byte[] buffer = new byte[data.Length]; data.Seek(0, SeekOrigin.Begin); data.Read(buffer, 0, (int)data.Length); context.Response.BinaryWrite(buffer); }