文章分类

站点统计

  • 分类总数: 13 个
  • 文章总数: 145 篇
  • 评论总数: 35 条
  • 附件总数: 59 个
  • 建站日期: 2008-08-18
  • 访问总数: 388498 人次
  • RSS订阅: 文章|评论

SharpZipLib使用示例

KY8 于 2009-03-27 23:53:31 发表.Net

SharpZipLib 是一个免费的Zip操作类库,可以利用它对 ZIP 等多种格式进行压缩与解压。SharpZipLib使用C#编写的,在VB.NET、C#或其他的.NET语言中都可以使用它创建Zip文件、并进行读取 和更新等操作。下载网址:http://www.icsharpcode.net/OpenSource/SharpZipLib /Download.aspx。目前的版本为0.85。

1、创建zip文件,并添加文件:

  1. using (ZipFile zip = ZipFile.Create(@"E:\test.zip")) 
  2.     zip.BeginUpdate(); 
  3.     zip.Add(@"E:\文件1.txt"); 
  4.     zip.Add(@"E:\文件2.txt"); 
  5.     zip.CommitUpdate(); 

2、将文件夹压缩为文件:
(new FastZip()).CreateZip(@"E:\test.zip", @"E:\test\", true, "");
最后一个参数是使用正则表达式表示的过滤文件规则。CreateZip方法有3个重载版本,其中有目录过滤参数、文件过滤参数及用于指定是否进行子目录递归的一个bool类型的参数。
3、将文件添加到已有zip文件中:
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    zip.BeginUpdate();
    zip.Add(@"E:\test.doc");
    zip.CommitUpdate();
}
4、列出zip文件中文件
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    string list = string.Empty;
    foreach (ZipEntry entry in zip)
    {
        list += entry.Name + "\r\n";
    }
    MessageBox.Show(list);
}
5、删除zip文件中的一个文件
using (ZipFile zip = new ZipFile(@"E:\test.zip"))
{
    zip.BeginUpdate();
    zip.Delete(@"test.doc");
    zip.Delete(@"test22.txt");
    zip.CommitUpdate();
}
6、解压zip文件中文件到指定目录下
(new FastZip()).ExtractZip(@"E:\test.zip", @"E:\test\", "");
7、常用类:
ZipInputStream、GZipInputStream用于解压缩Deflate、GZip格式流,ZipOutputStream、GZipOutputStream用于压缩Deflate、GZip格式流。
StreamUtil类包含了几个Stream处理辅助方法:
    ①、Copy(Stream, Stream, Byte[])用于从一个Stream对象中复制数据到另一Stream对象。有多个重写
    ②、ReadFully(Stream, Byte [])用于从Stream对象中读取所有的byte数据。有多个重写

被阅849次, 1票SharpZipLib 发表评论

Wildcard Matching in C#

KY8 于 2009-02-06 07:24:46 发表.Net

  1. public static bool Wildcard(string pattern, string input) 
  2.     return Wildcard(pattern, 0, input, 0, false); 
  3.  
  4. public static bool Wildcard(string pattern, string input, bool insensitive) 
  5.     return Wildcard(pattern, 0, input, 0, insensitive); 
  6.  
  7. private static bool Wildcard(string pattern, int p, string input, int i, bool insensitive) 
  8.     for(; ; ) 
  9.     { 
  10.         char ic = input[i]; 
  11.         char pc = pattern[p]; 
  12.         switch(pc) 
  13.         { 
  14.             case '?'
  15.                 break
  16.  
  17.             case '*'
  18.                 p++; 
  19.                 for(int j = i; j < input.Length; j++) 
  20.                 { 
  21.                     if(Wildcard(pattern, p, input, j, insensitive)) 
  22.                     { 
  23.                         return true
  24.                     } 
  25.                 } 
  26.                 return false
  27.  
  28.             default
  29.                 if(insensitive) 
  30.                 { 
  31.                     ic = char.ToLower(ic); 
  32.                     pc = char.ToLower(pc); 
  33.                 } 
  34.                 if(ic != pc) 
  35.                 { 
  36.                     return false
  37.                 } 
  38.                 break
  39.         } 
  40.         i++; 
  41.         p++; 
  42.         if(p >= pattern.Length) 
  43.         { 
  44.             if(i >= input.Length) 
  45.             { 
  46.                 return true
  47.             } 
  48.             return false
  49.         } 
  50.         else if(i >= input.Length) 
  51.         { 
  52.             return false
  53.         } 
  54.     } 
被阅511次, 0票WildCard 发表评论

几个支持Asp.net的小巧的Web Server

KY8 于 2009-02-06 07:16:49 发表.Net

Cassini,是Asp.net上的一个项目。但是好像只有.Net 1.0 的。最新的叫 WebDev.WebServer2.  在.NET 安装包下面就有(不知道是否可以随意发布?). Codeplex 上有一个 Cassini 的包装器,支持.NET2.0, 可以让你在计算机内针对任意目录,右键支持直接将其转变为虚拟目录,进行Web服务.

以下为几个有用的链接,有心进行Asp.net程序桌面移植的朋友,可以看看.

http://www.codeplex.com/WebServiceHoster  自己在桌面程序中支持 Asp.net Host, 基于Cassini

http://www.codeplex.com/CassiniWrapper

UltiDev Cassini Web Server: 不同与微软的那个 Cassini, 但是支持 .NET 目前所有的版本(1.0-3.5)

http://ultidev.com/products/Cassini/index.htm

其他应用文章

http://zhq.ahau.edu.cn/blog/article.asp?id=288

http://zhq.ahau.edu.cn/blog/article/297.htm

http://tv9.cnblogs.com/articles/73176.html

Mono XSP

http://www.mono-project.com/ASP.NET

Small and Reliable C++ HTTP Server with Complete ASP.NET Support

C# WebServer

被阅668次, 0票Asp.net Web Server 发表评论

判断当前ASP.NET的.NET Framework(CLR)版本

KY8 于 2009-01-29 02:02:42 发表.Net

可通过System.Environment.Version.ToString()取得当前CLR版本号,然后对照下表得到Revision版本:

.NET Framework version Revision Version
3.5 Original release 3.5.21022.8
3.5 Service Pack 1 3.5.30729.1
3.0 Original release 3.0.4506.30
3.0 Service Pack 1 3.0.4506.648
3.0 Service Pack 2 3.0.4506.2152
2.0 Original release 2.0.50727.42
2.0 Service Pack 1 2.0.50727.1433
2.0 Service Pack 2 2.0.50727.3053
1.1 Original release 1.1.4322.573
1.1 Service Pack 1 1.1.4322.2032
1.1 Service Pack 1 (Windows Server 2003 32-bit version*) 1.1.4322.2300
1.0 Original release 1.0.3705.0
1.0 Service Pack 1 1.0.3705.209
1.0 Service Pack 2 1.0.3705.288
1.0 Service Pack 3 1.0.3705.6018
*The Microsoft .NET Framework 1.1 is included with the 32-bit version of Windows Server 2003.

CodePlex.com上的三个ISO读写类库

KY8 于 2009-01-18 18:37:10 发表.Net

.NET DiscUtils

纯C#实现读写ISO和VHD文件的类库,以Stream进行文件读写,无需将整个文件加载到内存中。当前支持的文件系统格式:FAT、NTFS(只读)、VHD和VDI。范例:

①、新建一个ISO文件:

  1. CDBuilder builder = new CDBuilder(); 
  2. builder.UseJoliet = true
  3. builder.VolumeIdentifier = "A_SAMPLE_DISK"
  4. builder.AddFile(@"Folder\Hello.txt", Encoding.ASCII.GetBytes("Hello World!")); 
  5. builder.Build(@"C:\temp\sample.iso"); 

可以像上面那样以byte数组添加文件,也可以直接从Windows文件系统中加载,或者也可以是个Stream。生成的结果保存到Stream中,也可以直接保存到Windows的文件系统中。
②、从ISO文件中读取文件

  1. using (FileStream isoStream = File.Open(@"C:\temp\sample.iso")) 
  2.   CDReader cd = new CDReader(isoStream, true); 
  3.   Stream fileStream = cd.OpenFile(@"Folder\Hello.txt", FileMode.Open); 
  4.   // Use fileStream... 
  5.  

目录结构以cd.Root为起点。
③、新建一个虚拟硬盘:

  1. long diskSize = 30 * 1024 * 1024; //30MB 
  2.  
  3. using (Stream vhdStream = File.Create(@"C:\TEMP\mydisk.vhd")) 
  4.     Disk disk = Disk.InitializeDynamic(vhdStream, diskSize); 
  5.     BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat); 
  6.     using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null)) 
  7.     { 
  8.         fs.CreateDirectory(@"TestDir\CHILD"); 
  9.         // do other things with the file system... 
  10.  
  11.     } 

文件系统以fs.Root作为起点。
④、新建一个虚拟软盘:

  1. using (FileStream fs = File.Create(@"myfloppy.vfd")) 
  2.     using (FatFileSystem floppy = FatFileSystem.FormatFloppy(fs, FloppyDiskType.HighDensity, "MY FLOPPY  ")) 
  3.     { 
  4.         using (Stream s = floppy.OpenFile("foo.txt", FileMode.Create)) 
  5.         { 
  6.             // Use stream... 
  7.  
  8.         } 
  9.     } 

Image Master
用于读写iso文件的.Net应用程序,主要特性:
    * Read the contents of image files before burning them to disc.
    * Extract the contents of image files without burning them to disc.
    * Burn an image file to disc.
    * Burn files and/or folders directly to disc.
    * Supports multi-session burning.
    * Create image files for archiving.
    * Convert Bin Image Files (.bin), Nero Image Files (.nrg), Alcohol Image Files (.mdf), CloneCd Image Files (.img), DiscJuggler Image Files (.cdi) to iso images.


在Windows XP SP2刻录光盘需要安装Imapi v2.0,在Windows Vista默认就已经安装了。


GomuISO9660

C#实现的一个类库,用于操作ISO9660映像(.iso/.bin/.mdf...) ,主要特性:
    * Read ISO9660 discs images (supported formats are .iso/.bin/.mdf and CloneCd image).
    * Extract from discs images are by file or full.
    * Create an iso disc image file from CD/DVD source.
    * Convert from several disc image format to iso disc image file (supported formats are .bin/.mdf/.nrg/.img/.cdi).
    * Create iso disc image file from a source directory (not available yet).
    * Burn iso file.

被阅664次, 1票ISO CodePlex 发表评论

通过System.Data.SQLite.dll往SQLite数据库中插入Blob数据

KY8 于 2009-01-14 18:23:12 发表.Net

有两种方法可以实现:
①、通过SQLiteParameter

  1. static void TestSqliteBinary() 
  2.     using (SQLiteConnection cnn = new SQLiteConnection("data source=temp.db")) 
  3.     { 
  4.         cnn.Open(); 
  5.         using (SQLiteCommand cmd = cnn.CreateCommand()) 
  6.         { 
  7.             //cmd.CommandText = "Create Table test(data Image)"; 
  8.             //cmd.ExecuteNonQuery(); 
  9.  
  10.             cmd.CommandText = "insert into test values(@data)"
  11.             SQLiteParameter para = new SQLiteParameter("@data",DbType.Binary); 
  12.             string file = @"info.zip"
  13.             FileStream fs = new FileStream(file, FileMode.Open); 
  14.             StreamUtil su = new StreamUtil(); 
  15.  
  16.             byte[] buffer = su.StreamToBytes(fs); 
  17.             fs.Close(); 
  18.  
  19.             para.Value = buffer; 
  20.             cmd.Parameters.Add(para); 
  21.             cmd.ExecuteNonQuery(); 
  22.         } 
  23.     } 


②、通过16进制字符编码:

  1. INSERT INTO Foo (blob) VALUES(X'BADF00D'


In the above example, the binary data is quoted as hex, but inserted into the database as actual binary characters.  Data is retrieved as a byte[] array.

被阅1234次, 1票SQLite Blob 发表评论

完成了AStyle的.Net调用接口[AStyle.Net.Interface]

Admin 于 2008-10-18 13:41:26 发表.Net

下载AStyle.Net.Interface.rar,然后在项目中引用AStyle.Net.dll:

  1. string input = File.ReadAllText("in.txt"); 
  2. string temp = ""
  3. temp = AStyle.Net.Interface.Format(input, "--mode=cs --style=ansi --indent=tab"); 
  4. File.WriteAllText("out.txt",temp.Trim()); 

 

被阅932次, 0票AStyle 发表评论

在.NET中使用Berkeley DB

Admin 于 2008-10-12 10:54:57 发表.Net

Berkeley DB是历史悠久的嵌入式数据库系统,早期主要应用在UNIX/LINUX操作系统上,现在也有大量的Windows应用程序使用Berkeley DB存储数据。Berkeley DB的存储的是key/value键值对,可以理解为硬盘上的超级hash表,可以管理256TB数据,而且能支撑几千个并发访问。BerkeleyDB 相关资料可以从这里下载:http://www.oracle.com/technology/products/berkeley-db/index.html
    由于SQLite只支持单写多读,大多数情况下无法满足大访问量Web站点应用的并发性要求;而DB4O的Embed模式完全不支持并发;可以考虑使用Berkeley DB作为Asp.Net的Embed数据库。

目前Berkeley DB官方有C++版和Java版。要想在.NET中使用,可以使用Berkeley DB for .NET的Binding(Wrapper)。Berkeley DB for .NET 最 新版本为0.95,支持BDB 4.3和4.5。下载到libdb-dotnet_0_95.zip后,解压,在解压缩后的bin目录找到libdb_dotNET45.dll,这就是 BDB 4.5的.NET Binding,在.NET项目中引用此DLL就可以开始使用了。

被阅1003次, 0票Berkeley 发表评论
1 / 7 / 55 | « 1 2 3 4 » |
Powered by MiniBoke v2.0.0.8 Build 0828

Copyright © 2008 开源吧!. All rights reserved.

粤ICP备07500939号