因为家里网络原因,我通常在浏览一个网站后,就将网页关闭,然后在脱机状态观看内容。为了防止IE临时文件被清除,我想写个程序 能够直接把IE临时文件的内容,以一个网站一个网站的形式自动拷贝到我定义的文件夹里。(就如打开IE浏览器点文件再点另存为。。一样)不知道旅游没有朋友有这方面的经验 给点思路 谢谢
解决方案 »
- 如何实现一个表格控件,要求每个单元格可以支持图片,选择按扭,check按扭,普通按扭,图片按扭,组合框,每一行每列要求可以背景单独重绘
- 数据库超难的问题
- namespace中multipart 的问题
- 请教一个有关转换的问题(分不高请大家帮忙解决,谢谢了)?在线等
- 关于隐藏工具栏的问题,请大哥们指教
- 求助:关于在C# 中加入MediaPlayer组件的一点疑惑
- C#有没有SDK之类的东东?
- 如何获取视频流
- 如何实现不可变类型并实现赋值时创建新对象
- 大家推荐一本由webform转到winform的书呀。其他资料也行,谢谢了(C#)
- 想学.NET,大家给推荐本好书。急。
- 怎样把一个System.String类型转换为System.Web.UI.WebControls.TextBox类型
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;namespace FindIntranetIP
{
/// <summary>
/// Form3 的摘要说明。
/// </summary>
public class Form3 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button FileOk;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form3()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.FileOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// FileOk
//
this.FileOk.Location = new System.Drawing.Point(0, 0);
this.FileOk.Name = "FileOk";
this.FileOk.TabIndex = 0;
this.FileOk.Text = "OK";
this.FileOk.Click += new System.EventHandler(this.FileOk_Click);
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.FileOk);
this.Name = "Form3";
this.Text = "Form3";
this.ResumeLayout(false); }
#endregion #region 引入dll [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;
} [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct SYSTEMTIME
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
} [DllImport("kernel32.dll",SetLastError=true, CharSet=CharSet.Auto)]
public static extern int FileTimeToSystemTime(
IntPtr lpFileTime,
IntPtr lpSystemTime); [DllImport("wininet.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr FindFirstUrlCacheEntry(
[MarshalAs(UnmanagedType.LPTStr)] string lpszUrlSearchPattern,
IntPtr lpFirstCacheEntryInfo,
ref int lpdwFirstCacheEntryInfoBufferSize); [DllImport("wininet.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern bool FindNextUrlCacheEntry(
IntPtr hEnumHandle,
IntPtr lpNextCacheEntryInfo,
ref int lpdwNextCacheEntryInfoBufferSize); [DllImport("wininet.dll")]
public static extern bool FindCloseUrlCache(
IntPtr hEnumHandle); const int ERROR_NO_MORE_ITEMS = 259; #endregion
#region FileTimeToSystemTime private string FILETIMEtoDataTime(FILETIME time)
{
IntPtr filetime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(FILETIME)) );
IntPtr systime = Marshal.AllocHGlobal( Marshal.SizeOf(typeof(SYSTEMTIME)) );
Marshal.StructureToPtr(time,filetime,true);
FileTimeToSystemTime( filetime ,systime);
SYSTEMTIME st = (SYSTEMTIME) Marshal.PtrToStructure(systime,typeof(SYSTEMTIME));
string Time = st.wYear.ToString()+"."+st.wMonth.ToString()+"."+st.wDay.ToString()+"."+st.wHour.ToString()+"."+st.wMinute.ToString()+"."+st.wSecond.ToString();
return Time;
} #endregion private string GetNeedString(string initString, string seperator)
{
int lastIndex = initString.LastIndexOf(seperator);
return initString.Substring(lastIndex + 1); } private void FileOk_Click(object sender, System.EventArgs e)
{ int nNeeded = 0, nBufSize;
IntPtr buf;
INTERNET_CACHE_ENTRY_INFO CacheItem;
IntPtr hEnum;
bool r; FindFirstUrlCacheEntry( null, IntPtr.Zero, ref nNeeded ); if ( Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
return; nBufSize = nNeeded;
buf = Marshal.AllocHGlobal( nBufSize );
hEnum = FindFirstUrlCacheEntry( null, buf, ref nNeeded ); int num = 0;
while ( true )
{
num ++;
CacheItem = (INTERNET_CACHE_ENTRY_INFO) Marshal.PtrToStructure( buf,
typeof(INTERNET_CACHE_ENTRY_INFO) ); string modifiedTime = FILETIMEtoDataTime(CacheItem.LastModifiedTime);
string expireTime = FILETIMEtoDataTime(CacheItem.ExpireTime);
string accessTime = FILETIMEtoDataTime(CacheItem.LastAccessTime);
string syncTime = FILETIMEtoDataTime(CacheItem.LastSyncTime); #region 获得数据,存入数据库
string LocalFileName = Marshal.PtrToStringAuto(CacheItem.lpszLocalFileName); try
{ //此處遍歷CacheItem即可
//例如 http://wma.yymp3.com/new/twins27/3.wma
string fileextension = GetNeedString(LocalFileName, @".");
if (fileextension == "wma")
{
string filename = GetNeedString(LocalFileName, @"/"); string Source = LocalFileName;
string Destination = @"D:\J\music\temp" + filename;
File.Copy(Source, Destination, true);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion nNeeded = nBufSize;
r = FindNextUrlCacheEntry( hEnum, buf, ref nNeeded ); if ( !r && Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS )
break; if ( !r && nNeeded > nBufSize )
{
nBufSize = nNeeded;
buf = Marshal.ReAllocHGlobal( buf, (IntPtr) nBufSize );
FindNextUrlCacheEntry( hEnum, buf, ref nNeeded );
}
} MessageBox.Show("系统数据加载完毕!");
Marshal.FreeHGlobal( buf ); } }
}
可以遍历ie临时文件夹下的文件,而且可以查出文件名,网站地址等等属性
我本来想实现copy到另一个文件夹下的功能,不过没有实现,要请教其他高人的了