Mohammad__Shahid Ответов: 0

Можем ли мы генерировать миниатюры XLS и DOC в ASP.NET


Can we generate XLS and DOC Thumbnail in ASP.NET ?


I have used "ShellFile" Class to generate Thumbnail , However it is working fine for Excel files and Documents file and generates the Doc , Xls icons, I need first page copy as a thumbnail instead of Doc/xls icon.


Что я уже пробовал:

protected void BindGridview()
        {
            string[] filesPath = Directory.GetFiles(Server.MapPath("~/UploadedFiles/"));

            foreach (string path in filesPath)
            {
                if (Path.GetExtension(path) != ".bmp")
                {
                    //Xls
                    if (_xlsExt.Contains(Path.GetExtension(path)))
                    {
                        ShellFile shellFile = ShellFile.FromFilePath(path);
                        Bitmap bmp = new Bitmap(shellFile.Thumbnail.ExtraLargeBitmap);
                        bmp.Save(Server.MapPath("~/UploadedFiles/" + Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
                        files.Add(new FileArrays { FilePath = Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp", FileName = Path.GetFileNameWithoutExtension(path), FileType = "xls" });
                    }

                    //Doc
                    else if (_docExt.Contains(Path.GetExtension(path)))
                    {                        
                        ShellFile shellFile = ShellFile.FromFilePath(path);
                        Bitmap bmp = new Bitmap(shellFile.Thumbnail.ExtraLargeBitmap);
                        bmp.Save(Server.MapPath("~/UploadedFiles/" + Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
                        files.Add(new FileArrays { FilePath = Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp", FileName = Path.GetFileNameWithoutExtension(path), FileType = "doc" });
                    }

                    //Pdf , Image and Other
                    else
                    {
                        ShellFile shellFile = ShellFile.FromFilePath(path);
                        Bitmap bmp = new Bitmap(shellFile.Thumbnail.ExtraLargeBitmap);
                        bmp.Save(Server.MapPath("~/UploadedFiles/" + Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
                        files.Add(new FileArrays { FilePath = Path.GetFileNameWithoutExtension(path) + "_Thumb.bmp", FileName = Path.GetFileNameWithoutExtension(path), FileType = Path.GetExtension(path).Substring(1, (Path.GetExtension(path).Length)-1) });
                    }
                }
            }

            lsttableview.DataSource = files;
            lsttableview.DataBind();
        }

0 Ответов