Click here to Skip to main content
16,015,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


What I have tried:

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();
        }
Posted
Updated 30-Oct-17 20:39pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900