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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)