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); }
protected void ContentObjectFormView_ItemCommand(object sender, FormViewCommandEventArgs e) { switch (e.CommandName) { case "DownloadZip": Label IDLabel = (Label)FindControl("IDLabel"); Label LocationLabel = (Label)FindControl("LocationLabel"); vwarDAL.IDataRepository vd = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy();; vd.IncrementDownloads(ContentObjectID); string filePath = Website.Common.FormatZipFilePath(IDLabel.Text.Trim(), LocationLabel.Text.Trim()); string clientFileName = System.IO.Path.GetFileName(filePath); Website.Documents.ServeDocument(vd.GetContentFile(ContentObjectID, clientFileName), clientFileName); vd.Dispose(); vd = null; break; } }
public string UpdateThumbnailCache(string pid) { vwarDAL.IDataRepository dal = (new vwarDAL.DataAccessFactory()).CreateDataRepositorProxy(); foreach (vwarDAL.ContentObject co in allpids) { if (co.PID == pid) { try { System.IO.Stream screenshotdata = dal.GetContentFile(co.PID, co.ScreenShot); if (screenshotdata != null) { int length = (int)screenshotdata.Length; if (length != 0) { string ext = new FileInfo(co.ScreenShot).Extension.ToLower(); System.Drawing.Imaging.ImageFormat format; format = System.Drawing.Imaging.ImageFormat.Png; if (ext == ".png") { format = System.Drawing.Imaging.ImageFormat.Png; } else if (ext == ".jpg") { format = System.Drawing.Imaging.ImageFormat.Jpeg; } else if (ext == ".gif") { format = System.Drawing.Imaging.ImageFormat.Gif; } //Use the original file bytes to remain consistent with the new file upload ID creation for thumbnails co.ThumbnailId = Website.Common.GetFileSHA1AndSalt(screenshotdata) + ext; dal.UpdateContentObject(co); try { File.Delete(HttpContext.Current.Server.MapPath("~/thumbnails/" + co.ThumbnailId)); } catch (System.IO.FileNotFoundException t) { } using (FileStream outFile = new FileStream(HttpContext.Current.Server.MapPath("~/thumbnails/" + co.ThumbnailId), FileMode.Create)) Website.Common.GenerateThumbnail(screenshotdata, outFile, format); } else { dal.Dispose(); return("No screenshot data"); } } else { dal.Dispose(); return("No screenshot data"); } } catch (System.Exception ex) { return(ex.Message); } } } dal.Dispose(); return("OK"); }