示例#1
0
        public Object GetThumbnail(String uniqueName)
        {
            var rootPath = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles");

            var FileDTO      = FileBO.GetFileByUniqueName(uniqueName);
            var fileFullPath = Path.Combine(rootPath, FileDTO.UniqueName + FileDTO.FileExt);

            ShellFile shellFile  = ShellFile.FromFilePath(fileFullPath);
            Bitmap    shellThumb = shellFile.Thumbnail.MediumBitmap;

            if (FileDTO != null)
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

                byte[] file = ImageToBytes(shellThumb); // Call to private function ImageToBytes

                MemoryStream ms = new MemoryStream(file);

                response.Content = new ByteArrayContent(file);
                response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");

                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(FileDTO.ContentType);
                response.Content.Headers.ContentDisposition.FileName = FileDTO.Name;
                return(response);
            }
            else
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(response);
            }
        }
示例#2
0
        public Object DownloadFile(String uname)
        {
            var rootPath = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles");
            var dto      = FileBO.GetFileByUniqueName(uname);

            if (dto != null)
            {
                HttpResponseMessage response = new  HttpResponseMessage(HttpStatusCode.OK);
                var    fileFullPath          = System.IO.Path.Combine(rootPath, dto.UniqueName + dto.FileExt);
                byte[] file = System.IO.File.ReadAllBytes(fileFullPath);
                System.IO.MemoryStream ms = new System.IO.MemoryStream(file);

                response.Content = new ByteArrayContent(file);
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");

                response.Content.Headers.ContentType = new MediaTypeHeaderValue(dto.ContentType);
                response.Content.Headers.ContentDisposition.FileName = dto.Name;
                return(response);
            }
            else
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(response);
            }
        }