Пример #1
0
        public Object getThumbnail(string uniqueName)
        {
            FolderBAL fb           = new FolderBAL();
            FileDTO   filedto      = fb.GetFileByUniqueID(uniqueName);
            var       rootPath     = HttpContext.Current.Server.MapPath("~/UploadedFiles");
            var       fileFullPath = System.IO.Path.Combine(rootPath, uniqueName);

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

            if (filedto != null)
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                byte[]       file            = ImageToBytes(shellThumb);
                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.ContentTpye);
                response.Content.Headers.ContentDisposition.FileName = filedto.FileUniqueName;
                return(response);
            }
            else
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(response);
            }
        }
Пример #2
0
        public Object DownloadFile(String UniqueName)
        {
            var       rootpath = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles");
            FolderBAL fb       = new FolderBAL();
            var       fileDTO  = fb.GetFileByUniqueID(UniqueName);

            if (fileDTO != null)
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                var    filefullpath          = System.IO.Path.Combine(rootpath, fileDTO.FileUniqueName);
                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(fileDTO.ContentTpye);
                response.Content.Headers.ContentDisposition.FileName = fileDTO.fileActualName;
                return(response);
            }
            else
            {
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound);
                return(response);
            }
        }