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

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

请先到这里下载一个控件

ThumbDBLib

A C# library for reading thumbs.db file

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

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

<!-- {cps..0}--> < form id ="form1" runat ="server" > < div > < asp:PlaceHolder id ="plcThumbs" runat ="server" EnableViewState ="False" ></ asp:PlaceHolder > </ div > </ form >

VB主要代码:

Dim ThumbDb As String = Server.MapPath( " . " ) & " /thumbs.db " If System.IO.File.Exists(ThumbDb) Then Dim ThumbLib As New ThumbDBLib.ThumbDB(ThumbDb) If Not Request.QueryString( " thumb " ) Is Nothing Then Dim Thumb As String = Request.QueryString( " thumb " ) Dim ThumbData As Byte () = ThumbLib.GetThumbData(Thumb) Response.Clear() Response.ContentType = " image/ " & System.IO.Path.GetExtension(Thumb).ToLower.Replace( " . " , "" ) Response.BinaryWrite(ThumbData) Response.Flush() Response.End() Else For Each thumb As String In ThumbLib.GetThumbfiles If System.IO.File.Exists(Server.MapPath( " . " ) & " / " & thumb) Then ' Could use a Literal control here if you want more ' control over the html. Dim ThumbImage As New System.Web.UI.WebControls.Image ThumbImage.ImageUrl = " thumbs.aspx?thumb= " & Server.UrlEncode(thumb) ThumbImage.ImageAlign = ImageAlign.Top ThumbImage.AlternateText = thumb ThumbImage.BorderStyle = BorderStyle.Outset ThumbImage.BorderWidth = New Unit( 1 ) ThumbImage.Attributes.Add( " hspace " , " 4 " ) ThumbImage.Attributes.Add( " vspace " , " 4 " ) ThumbImage.Attributes.Add( " onclick " , " window.location.href=' " & thumb & " '; " ) ThumbImage.Style.Add( " cursor " , " hand " ) plcThumbs.Controls.Add(ThumbImage) End If Next End If ThumbLib = Nothing Else Response.Write( " Thumbs.db Not Found! " ) End If
<!-- {cps..1}-->如何读取thumbs.db里的缩略图?(downmoon) Dim ThumbDb As String = Server.MapPath( " . " ) & " /thumbs.db "
如何读取thumbs.db里的缩略图?(downmoon)
If System.IO.File.Exists(ThumbDb) Then
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
Dim ThumbLib As New ThumbDBLib.ThumbDB(ThumbDb)
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
If Not Request.QueryString( " thumb " ) Is Nothing Then
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
Dim Thumb As String = Request.QueryString( " thumb " )
如何读取thumbs.db里的缩略图?(downmoon)
Dim ThumbData As Byte () = ThumbLib.GetThumbData(Thumb)
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon) Response.Clear()
如何读取thumbs.db里的缩略图?(downmoon) Response.ContentType
= " image/ " & System.IO.Path.GetExtension(Thumb).ToLower.Replace( " . " , "" )
如何读取thumbs.db里的缩略图?(downmoon) Response.BinaryWrite(ThumbData)
如何读取thumbs.db里的缩略图?(downmoon) Response.Flush()
如何读取thumbs.db里的缩略图?(downmoon) Response.End()
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
Else
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
For Each thumb As String In ThumbLib.GetThumbfiles
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
If System.IO.File.Exists(Server.MapPath( " . " ) & " / " & thumb) Then
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
' CoulduseaLiteralcontrolhereifyouwantmore
如何读取thumbs.db里的缩略图?(downmoon)
' controloverthehtml.
如何读取thumbs.db里的缩略图?(downmoon)
Dim ThumbImage As New System.Web.UI.WebControls.Image
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.ImageUrl
= " thumbs.aspx?thumb= " & Server.UrlEncode(thumb)
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.ImageAlign
= ImageAlign.Top
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.AlternateText
= thumb
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.BorderStyle
= BorderStyle.Outset
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.BorderWidth
= New Unit( 1 )
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.Attributes.Add(
" hspace " , " 4 " )
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.Attributes.Add(
" vspace " , " 4 " )
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.Attributes.Add(
" onclick " , " window.location.href=' " & thumb & " '; " )
如何读取thumbs.db里的缩略图?(downmoon) ThumbImage.Style.Add(
" cursor " , " hand " )
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon) plcThumbs.Controls.Add(ThumbImage)
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
End If
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
Next
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
End If
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon) ThumbLib
= Nothing
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
Else
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon) Response.Write(
" Thumbs.dbNotFound! " )
如何读取thumbs.db里的缩略图?(downmoon)
如何读取thumbs.db里的缩略图?(downmoon)
End If

C#主要代码:

string ThumbDb = Server.MapPath( " . " ) + " //thumbs.db " ; if (System.IO.File.Exists(ThumbDb)) { ThumbDBLib.ThumbDB ThumbLib = new ThumbDBLib.ThumbDB(ThumbDb); if ((Request.QueryString[ " thumb " ] != null )) { string Thumb = Request.QueryString[ " thumb " ]; byte [] ThumbData = ThumbLib.GetThumbData(Thumb); Response.Clear(); Response.ContentType = " image/ " + System.IO.Path.GetExtension(Thumb).ToLower().Replace( " . " , "" ); Response.BinaryWrite(ThumbData); Response.Flush(); Response.End(); } else { foreach ( string thumb in ThumbLib.GetThumbfiles()) { if (System.IO.File.Exists(Server.MapPath( " . " ) + " // " + thumb)) { // Could use a Literal control here if you want more // control over the html. System.Web.UI.WebControls.Image ThumbImage = new System.Web.UI.WebControls.Image(); ThumbImage.ImageUrl = " thumbs.aspx?thumb= " + Server.UrlEncode(thumb); ThumbImage.ImageAlign = ImageAlign.Top; ThumbImage.AlternateText = thumb; ThumbImage.BorderStyle = BorderStyle.Outset; ThumbImage.BorderWidth = new Unit( 1 ); ThumbImage.Attributes.Add( " hspace " , " 4 " ); ThumbImage.Attributes.Add( " vspace " , " 4 " ); ThumbImage.Attributes.Add( " onclick " , " window.location.href=' " + thumb + " '; " ); ThumbImage.Style.Add( " cursor " , " hand " ); plcThumbs.Controls.Add(ThumbImage); } } } ThumbLib = null ; } else { Response.Write( " Thumbs.db Not Found! " ); } xt 和 image 数据类型。
浏览效果如图:

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

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