问题:如何读取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为plcThumbs的PlaceHolder
<
form
id
="form1"
runat
="server"
>
<
div
>
<
asp:PlaceHolder
id
="plcThumbs"
runat
="server"
EnableViewState
="False"
>
asp:PlaceHolder
>
div
>
form
>
VB主要代码:
Code
Dim ThumbDb As String = Server.MapPath(".") & "\thumbs.db"
If System.IO.File.Exists(ThumbDb) Then
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Dim ThumbLib As New ThumbDBLib.ThumbDB(ThumbDb)
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
If Not Request.QueryString("thumb") Is Nothing Then
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Dim Thumb As String = Request.QueryString("thumb")
Dim ThumbData As Byte() = ThumbLib.GetThumbData(Thumb)
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Response.Clear()
Response.ContentType = "image/" & System.IO.Path.GetExtension(Thumb).ToLower.Replace(".", "")
Response.BinaryWrite(ThumbData)
Response.Flush()
Response.End()
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Else
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
For Each thumb As String In ThumbLib.GetThumbfiles
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
If System.IO.File.Exists(Server.MapPath(".") & "\" & thumb) Then
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
' Could use a Literal control here if you want more
' control over the html.
Dim ThumbImage As New System.Web.UI.WebControls.Image
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
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")
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
plcThumbs.Controls.Add(ThumbImage)
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
End If
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Next
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
End If
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
ThumbLib = Nothing
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Else
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
Response.Write("Thumbs.db Not Found!")
![None.gif](http://img.e-com-net.com/image/info8/7da3525d42b249f380f90d23d1eaafba.gif)
End If
C#主要代码:
Code
string ThumbDb = Server.MapPath(".") + "\\thumbs.db";
if (System.IO.File.Exists(ThumbDb))
![ExpandedBlockStart.gif](http://img.e-com-net.com/image/info8/a851f6ebab08498cbe1d2f2c2b23a0c9.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
ThumbDBLib.ThumbDB ThumbLib = new ThumbDBLib.ThumbDB(ThumbDb);
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
if ((Request.QueryString["thumb"] != null))
![ExpandedSubBlockStart.gif](http://img.e-com-net.com/image/info8/c258b09401044c33a0d619608a74e55d.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
string Thumb = Request.QueryString["thumb"];
byte[] ThumbData = ThumbLib.GetThumbData(Thumb);
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
Response.Clear();
Response.ContentType = "image/" + System.IO.Path.GetExtension(Thumb).ToLower().Replace(".", "");
Response.BinaryWrite(ThumbData);
Response.Flush();
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
Response.End();
}
else
![ExpandedSubBlockStart.gif](http://img.e-com-net.com/image/info8/c258b09401044c33a0d619608a74e55d.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
foreach (string thumb in ThumbLib.GetThumbfiles())
![ExpandedSubBlockStart.gif](http://img.e-com-net.com/image/info8/c258b09401044c33a0d619608a74e55d.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
if (System.IO.File.Exists(Server.MapPath(".") + "\\" + thumb))
![ExpandedSubBlockStart.gif](http://img.e-com-net.com/image/info8/c258b09401044c33a0d619608a74e55d.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
// 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();
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
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");
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
plcThumbs.Controls.Add(ThumbImage);
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
}
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
}
}
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
ThumbLib = null;
}
else
![ExpandedBlockStart.gif](http://img.e-com-net.com/image/info8/a851f6ebab08498cbe1d2f2c2b23a0c9.gif)
{
![InBlock.gif](http://img.e-com-net.com/image/info8/631f42b035dc4497b25c141371b40678.gif)
Response.Write("Thumbs.db Not Found!");
}
浏览效果如图:
![如何读取thumbs.db里的缩略图?(downmoon)_第1张图片](http://img.e-com-net.com/image/info8/6522eebbe1dd48fcb4752e15bf797a6b.jpg)
完毕。
源码可以在这里下载