[攒分贴]每日小知识

jinjazz 2008-07-14 03:12:54
wininet.dll示例4:根据url获取ie缓存文件

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication34
{
class Program
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct internet_cache_entry_info
{
public int dwstructsize;
public IntPtr lpszsourceurlname;
public IntPtr lpszlocalfilename;
public int cacheentrytype;
public int dwusecount;
public int dwhitrate;
public int dwsizelow;
public int dwsizehigh;
public FILETIME lastmodifiedtime;
public FILETIME expiretime;
public FILETIME lastaccesstime;
public FILETIME lastsynctime;
public IntPtr lpheaderinfo;
public int dwheaderinfosize;
public IntPtr lpszfileextension;
public int dwexemptdelta;
}
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstUrlCacheEntry([MarshalAs(UnmanagedType.LPTStr)] string urlsearchpattern, IntPtr lpfirstcacheentryinfo, ref int lpdwfirstcacheentryinfobuffersize);
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool GetUrlCacheEntryInfo([MarshalAs(UnmanagedType.LPTStr)] string lpszurlname, IntPtr lpcacheentryinfo, ref int lpdwcacheentryinfobuffersize);
public static string getcatchfilename(string url)
{
int nneeded = 0, nbufsize = 0;
IntPtr buf = IntPtr.Zero;
FindFirstUrlCacheEntry(null, IntPtr.Zero, ref nneeded);
nbufsize = nneeded; buf = Marshal.AllocHGlobal(nbufsize);
internet_cache_entry_info cacheitem;
GetUrlCacheEntryInfo(url, buf, ref nneeded);
cacheitem = (internet_cache_entry_info)Marshal.PtrToStructure(buf, typeof(internet_cache_entry_info));
string res = Marshal.PtrToStringAuto(cacheitem.lpszlocalfilename);
return (res);
}

static void Main(string[] args)
{
string str = getcatchfilename("http://profile.csdn.net/jinjazz/picture/2.jpg");
Console.WriteLine(str);
Console.Read();
}
}
}


--------------------------------------------------------
很多人发蛋贴攒分,我也发发,但是有1分,发了也不能白发,我会随口说个技术基础点,不只局限于代码。
高手可以忽略本贴
...全文
137 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yilanwuyu123 2008-07-14
  • 打赏
  • 举报
回复
非高手接分。
初吻给了烟 2008-07-14
  • 打赏
  • 举报
回复
代码我保存了!!!顶

110,017

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧