如何读取thumbs.db里的缩略图?(downmoon)

问题:如何读取thumbs.db里的缩略图?

请先到这里下载一个控件

ThumbDBLib

A C# library for reading thumbs.db files

http://www.petedavis.net/MySite/DynPageView.aspx?pageid=31

引用dll,这里提供了 VB和C#代码,一个Thumbs.aspx,添加一个ID为plcThumbsPlaceHolder  

  < form  id ="form1"  runat ="server" >
    
< div >
    
< asp:PlaceHolder  id ="plcThumbs"  runat ="server"  EnableViewState ="False" > asp:PlaceHolder >
    
div >
    
form >

 
VB主要代码:

ContractedBlock.gif ExpandedBlockStart.gif Code
None.gif Dim ThumbDb As String = Server.MapPath("."& "\thumbs.db"
None.gif        
If System.IO.File.Exists(ThumbDb) Then
None.gif
None.gif            
Dim ThumbLib As New ThumbDBLib.ThumbDB(ThumbDb)
None.gif
None.gif            
If Not Request.QueryString("thumb"Is Nothing Then
None.gif
None.gif                
Dim Thumb As String = Request.QueryString("thumb")
None.gif                
Dim ThumbData As Byte() = ThumbLib.GetThumbData(Thumb)
None.gif
None.gif                Response.Clear()
None.gif                Response.ContentType 
= "image/" & System.IO.Path.GetExtension(Thumb).ToLower.Replace(".""")
None.gif                Response.BinaryWrite(ThumbData)
None.gif                Response.Flush()
None.gif                Response.End()
None.gif
None.gif            
Else
None.gif
None.gif                
For Each thumb As String In ThumbLib.GetThumbfiles
None.gif
None.gif                    
If System.IO.File.Exists(Server.MapPath("."& "\" & thumb) Then
None.gif
None.gif                        
' Could use a Literal control here if you want more 
None.gif
                        ' control over the html.
None.gif
                        Dim ThumbImage As New System.Web.UI.WebControls.Image
None.gif
None.gif                        ThumbImage.ImageUrl 
= "thumbs.aspx?thumb=" & Server.UrlEncode(thumb)
None.gif                        ThumbImage.ImageAlign 
= ImageAlign.Top
None.gif                        ThumbImage.AlternateText 
= thumb
None.gif                        ThumbImage.BorderStyle 
= BorderStyle.Outset
None.gif                        ThumbImage.BorderWidth 
= New Unit(1)
None.gif                        ThumbImage.Attributes.Add(
"hspace""4")
None.gif                        ThumbImage.Attributes.Add(
"vspace""4")
None.gif                        ThumbImage.Attributes.Add(
"onclick""window.location.href='" & thumb & "';")
None.gif                        ThumbImage.Style.Add(
"cursor""hand")
None.gif
None.gif                        plcThumbs.Controls.Add(ThumbImage)
None.gif
None.gif                    
End If
None.gif
None.gif                
Next
None.gif
None.gif            
End If
None.gif
None.gif            ThumbLib 
= Nothing
None.gif
None.gif        
Else
None.gif
None.gif            Response.Write(
"Thumbs.db Not Found!")
None.gif
None.gif        
End If


C#主要代码:

ContractedBlock.gif ExpandedBlockStart.gif Code
None.gif string ThumbDb = Server.MapPath("."+ "\\thumbs.db";
None.gif            
if (System.IO.File.Exists(ThumbDb))
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                ThumbDBLib.ThumbDB ThumbLib 
= new ThumbDBLib.ThumbDB(ThumbDb);
InBlock.gif
InBlock.gif                
if ((Request.QueryString["thumb"!= null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif
InBlock.gif                    
string Thumb = Request.QueryString["thumb"];
InBlock.gif                    
byte[] ThumbData = ThumbLib.GetThumbData(Thumb);
InBlock.gif
InBlock.gif                    Response.Clear();
InBlock.gif                    Response.ContentType 
= "image/" + System.IO.Path.GetExtension(Thumb).ToLower().Replace(".""");
InBlock.gif                    Response.BinaryWrite(ThumbData);
InBlock.gif                    Response.Flush();
InBlock.gif
InBlock.gif                    Response.End();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif
InBlock.gif                    
foreach (string thumb in ThumbLib.GetThumbfiles())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif
InBlock.gif                        
if (System.IO.File.Exists(Server.MapPath("."+ "\\" + thumb))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
// Could use a Literal control here if you want more 
InBlock.gif                            
// control over the html.
InBlock.gif
                            System.Web.UI.WebControls.Image ThumbImage = new System.Web.UI.WebControls.Image();
InBlock.gif
InBlock.gif                            ThumbImage.ImageUrl 
= "thumbs.aspx?thumb=" + Server.UrlEncode(thumb);
InBlock.gif                            ThumbImage.ImageAlign 
= ImageAlign.Top;
InBlock.gif                            ThumbImage.AlternateText 
= thumb;
InBlock.gif                            ThumbImage.BorderStyle 
= BorderStyle.Outset;
InBlock.gif                            ThumbImage.BorderWidth 
= new Unit(1);
InBlock.gif                            ThumbImage.Attributes.Add(
"hspace""4");
InBlock.gif                            ThumbImage.Attributes.Add(
"vspace""4");
InBlock.gif                            ThumbImage.Attributes.Add(
"onclick""window.location.href='" + thumb + "';");
InBlock.gif                            ThumbImage.Style.Add(
"cursor""hand");
InBlock.gif
InBlock.gif
InBlock.gif                            plcThumbs.Controls.Add(ThumbImage);
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif
InBlock.gif                ThumbLib 
= null;
ExpandedBlockEnd.gif            }

None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif               Response.Write(
"Thumbs.db Not Found!");
ExpandedBlockEnd.gif            }

 
浏览效果如图:

 如何读取thumbs.db里的缩略图?(downmoon)_第1张图片

 完毕。
源码可以在这里下载

转载于:https://www.cnblogs.com/downmoon/archive/2009/06/04/1495915.html

你可能感兴趣的:(如何读取thumbs.db里的缩略图?(downmoon))