• 5899 阅读
  • 18 回复

.net 常用类收集 [置顶]

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
本主题由 张小鱼 于 2010/3/18 11:42:00 执行 设置置顶 [查看记录]
C# 常用类库:
您是游客您没有权限查看该图片


C#常用类库.rar (您是游客您没有权限下载)


您是游客您没有权限查看该图片


C#常用类.zip (您是游客您没有权限下载)


您是游客您没有权限查看该图片


C#常用类大全.rar (您是游客您没有权限下载)
本帖最后由 张小鱼 于 2010-03-18 11:42 编辑
小鱼的淘宝店铺-多多支持哇
视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
您是游客您没有权限查看该图片


您是游客您没有权限查看该图片


您是游客您没有权限查看该图片


下载:
CbfCollection.rar (您是游客您没有权限下载)


来源: 阿发采集器源码
本帖最后由 张小鱼 于 2010-03-18 11:30 编辑
小鱼的淘宝店铺-多多支持哇

缓存roycms

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
您是游客您没有权限查看该图片


下载:
roycms.rar (您是游客您没有权限下载)

您是游客您没有权限查看该图片


下载:
ROYcms.Common.rar (您是游客您没有权限下载)
本帖最后由 张小鱼 于 2010-03-18 11:34 编辑
小鱼的淘宝店铺-多多支持哇

RedGlovePermission

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
您是游客您没有权限查看该图片


下载:
RedGlovePermission.rar (您是游客您没有权限下载)
小鱼的淘宝店铺-多多支持哇

赫阳新闻系统

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
您是游客您没有权限查看该图片


下载:
Utils.cs (您是游客您没有权限下载)
小鱼的淘宝店铺-多多支持哇

CacheManager

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
您是游客您没有权限查看该图片


CacheManager.cs (您是游客您没有权限下载)
小鱼的淘宝店铺-多多支持哇

SubStringHTML

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)

代码 复制 - 运行


using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Collections; 

/// <summary> 
/// SubStringHTML 的摘要说明 
/// </summary> 
public class SubStringHTML 
{ 
    public SubStringHTML() 
    { 
        // 
        // TODO: 在此处添加构造函数逻辑 
        // 
    } 
    public String subStringHTML(String param, int length, String end) 
    { 
        StringBuilder result = new StringBuilder(); 
        int n = 0; 
        string temp; 
        Boolean isCode = false; //是不是HTML代码 
        Boolean isHTML = false; //是不是HTML特殊字符,如  
        for (int i = 0; i < param.Length; i++) 
        { 
            temp = param[i].ToString(); 
            if (temp == "<") 
            { 
                isCode = true; 
            } 
            else if (temp == "&") 
            { 
                isHTML = true; 
            } 
            else if (temp == ">" && isCode) 
            { 
                n = n - 1; 
                isCode = false; 
            } 
            else if (temp == ";" && isHTML) 
            { 
                isHTML = false; 
            } 

            if (!isCode && !isHTML) 
            { 
                n = n + 1; 
                //UNICODE码字符占两个字节 

                if (Encoding.Default.GetBytes(temp).Length > 1) 
                { 
                    n = n + 1; 
                } 
            } 

            result.Append(temp); 
            if (n >= length) 
            { 
                break; 
            } 
        } 
        result.Append(end); 
        //取出截取字符串中的HTML标记 
        String temp_result = result.ToString(); 
        //去掉HTML标记属性 
        string[] HtmlTag = new string[] { "p", "div", "span", "table", "ul", "font", "b", "u", "i", "a", "h1", "h2", "h3", "h4", "h5", "h6" }; 
        for (int k = 0; k < HtmlTag.Length; k++) 
        { 

            temp_result = Regex.Replace(temp_result, "<(   )*" + HtmlTag[k] + "([^>])*>", "<" + HtmlTag[k] + ">", RegexOptions.IgnoreCase); 
            temp_result = Regex.Replace(temp_result, "(<(   )*(/)(   )*" + HtmlTag[k] + "(   )*>)", "</" + HtmlTag[k] + ">", RegexOptions.IgnoreCase); 
            //去掉成对的HTML标记 
            temp_result = Regex.Replace(temp_result, "<" + HtmlTag[k] + ">(.*?)</" + HtmlTag[k] + ">", ""); 
        } 

        Regex p = new Regex("<([a-zA-Z]+)[^<>]*>");//里面放正则表达式 
        MatchCollection m = p.Matches(temp_result);//如果想得到匹配的多个值,就用集合 



        ArrayList endHTML = new ArrayList(); 

        foreach (Match ms in m) 
        { 
            endHTML.Add(ms.ToString().Replace("<", "").Replace(">", "")); 
        } 
        for (int i = endHTML.Count - 1; i >= 0; i--) 
        { 
            result.Append("</"); 
            result.Append(endHTML[i].ToString()); 
            result.Append(">"); 
        } 

        return result.ToString(); 
    } 
} 



代码 复制 - 运行


 Public Function FormatUrl(ByVal str) 
  If Not IsNull(str) And Trim(str) <> "" And LCase(str) <> "http://" And Len(str) < 255 Then 
   str = Trim(Replace(Replace(Replace(Replace(str, vbNewLine, ""), Chr(9), ""), Chr(39), ""), Chr(34), "")) 
   If InStr(str, "://") > 0 Then 
    FormatUrl = str 
   Else 
    FormatUrl = "http://" & str 
   End If 
  Else 
   FormatUrl = "" 
  End If 
 End Function 
 Public Function GotTopic(ByVal str, ByVal strLen) 
  Dim l, t, c, i 
  Dim strTemp 
  On Error Resume Next 
  str = Trim(str) 
  str = Replace(str, " ", " ") 
  str = Replace(str, ">", ">") 
  str = Replace(str, "<", "<") 
  str = Replace(str, ">", ">") 
  str = Replace(str, "<", "<") 
  str = Replace(str, "'", "'") 
  str = Replace(str, """, Chr(34)) 
  str = Replace(str, vbNewLine, "") 
  l = Len(str) 
  t = 0 
  For i = 1 To l 
   c = Abs(Asc(Mid(str, i, 1))) 
   If c > 255 Then 
    t = t + 2 
   Else 
    t = t + 1 
   End If 
   If t >= strLen Then 
    strTemp = Left(str, i) & "..." 
    Exit For 
   Else 
    strTemp = str & "" 
   End If 
  Next 
  GotTopic = strTemp 
 End Function 
 Public Function CutTitle(ByVal str, ByVal strLen) 
  Dim l,m 
  Dim strTemp 
  str = Trim(str & "") 
  If strLen < 2 Then 
   CutTitle = str 
   Exit Function 
  End If 
  str = Replace(str, " ", " ") 
  str = Replace(str, ">", ">") 
  str = Replace(str, "<", "<") 
  str = Replace(str, ">", ">") 
  str = Replace(str, "<", "<") 
  str = Replace(str, "'", "'") 
  str = Replace(str, """, Chr(34)) 
  str = Replace(str, "&", "&") 
  str = Replace(str, vbNewLine, "") 
  str = Left(str,255) 
  If strLength(str) > strLen Then 
   l = strLen \ 2 
   m = strLen mod 2 
   strTemp = Left(str,l) & "..." & Right(str,l+m) 
  Else 
   strTemp = str 
  End If 
  CutTitle = strTemp 
 End Function 


public function htmlencode(fstring)  
if not isnull(fstring) then  
fstring = replace(fstring, ">", ">")  
fstring = replace(fstring, "<", "<")  
fstring = replace(fstring, chr(32), " ")    
fstring = replace(fstring, chr(9), " ")    
fstring = replace(fstring, chr(34), """)  
fstring = replace(fstring, chr(39), "'") 单引号过滤  
fstring = replace(fstring, chr(13), "")  
fstring = replace(fstring, chr(10) & chr(10), "</p><p> ")  
fstring = replace(fstring, chr(10), "<br> ")  
htmlencode = fstring  
end if  
end function 
本帖最后由 张小鱼 于 2010-03-26 08:47 编辑
小鱼的淘宝店铺-多多支持哇

asp.net 比较两个时间,返回时间间隔

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)

代码 复制 - 运行


using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 

/// <summary> 
/// 比较两个时间,返回时间间隔 
/// </summary> 
namespace CBF.Common 
{ 
    public class DateTimeDiff 
    { 
        public DateTimeDiff() 
        { 
            // 
            // TODO: 在此处添加构造函数逻辑 
            // 
        } 
        /// <summary> 
        /// 把秒转换成分钟 
        /// </summary> 
        /// <returns></returns> 
        public static int SecondToMinute(int Second) 
        { 
            decimal mm = (decimal)((decimal)Second / (decimal)60); 
            return Convert.ToInt32(Math.Ceiling(mm)); 
        } 
        /// <summary> 
        /// 计算两个时间的时间间隔 
        /// </summary> 
        /// <param name="DateTimeOld">较早的日期和时间</param> 
        /// <param name="DateTimeNew">较后的日期和时间</param> 
        /// <returns></returns> 
        public static string DateDiff(DateTime DateTimeOld, DateTime DateTimeNew) 
        { 
            string dateDiff = ""; 
            TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks); 
            TimeSpan ts2 = new TimeSpan(DateTimeNew.Ticks); 
            TimeSpan ts = ts1.Subtract(ts2).Duration(); 
            int day = ts.Days; 
            int hou = ts.Hours; 
            int minu = ts.Minutes; 
            int sec = ts.Seconds; 
            if (day > 0) 
            { 
                if (day > 30) 
                { 
                    if (day > 364) 
                    { 
                        dateDiff += day /365 + "年"; 
                    } 
                    else 
                    { 
                        dateDiff += day/30 + "个月"; 
                    } 
                } 
                else 
                { 
                    dateDiff += day.ToString() + "天"; 
                } 
            } 
            else 
            { 
                if (hou > 0) 
                { 
                    dateDiff += hou.ToString() + "小时"; 
                } 
                else 
                { 
                    if (minu > 0) 
                    { 
                        dateDiff += minu.ToString() + "分钟"; 
                    } 
                    else 
                    { 
                        if (sec > 0) 
                        { 
                            dateDiff += sec.ToString() + "秒"; 
                        } 
                        else 
                        { 
                            dateDiff += "0秒"; 
                        } 
                    } 
                } 
            } 
            if (DateTimeNew.CompareTo(DateTimeOld)>0) 
            { 
                dateDiff += "前"; 
            } 
            else 
            { 
                dateDiff += "后"; 
            } 
            return dateDiff; 
        } 
        /// <summary> 
        ///判断是否于5分钟之前 
        /// </summary> 
        /// <param name="DateTimeOld">较早的日期和时间</param> 
        /// <returns></returns> 
        public static bool DateDiff_minu(DateTime DateTimeOld) 
        { 
            TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks); 
            TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); 
            TimeSpan ts = ts1.Subtract(ts2).Duration(); 
            int minu = ts.Minutes; 
            if (minu > 5) 
            { 
                return true; 
            } 
            else 
            { 
                return false; 
            } 
        } 
        /// <summary> 
        /// 与当前时间比较,重载时间比较函数,只有一个参数 
        /// </summary> 
        /// <param name="DateTimeOld">较早的日期和时间</param> 
        /// <returns></returns> 
        public static string DateDiff(DateTime DateTimeOld) 
        { 
            return DateDiff(DateTimeOld, DateTime.Now); 
        } 
        /// <summary> 
        /// 日期比较,返回精确的几分几秒 
        /// </summary> 
        /// <param name="DateTime1">较早的日期和时间</param> 
        /// <param name="DateTime2">较迟的日期和时间</param> 
        /// <returns></returns> 
        public static string DateDiff_full(DateTime DateTime1, DateTime DateTime2) 
        { 
            string dateDiff = null; 
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); 
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); 
            TimeSpan ts = ts1.Subtract(ts2).Duration(); 
            dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒"; 
            return dateDiff; 
        } 
        /// <summary> 
        /// 时间比较,返回精确的几秒 
        /// </summary> 
        /// <param name="DateTime1">较早的日期和时间</param> 
        /// <param name="DateTime2">较迟的日期和时间</param> 
        /// <returns></returns> 
        public static int DateDiff_Sec(DateTime DateTime1, DateTime DateTime2) 
        { 
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); 
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks); 
            TimeSpan ts = ts1.Subtract(ts2).Duration(); 
            int dateDiff = ts.Days * 86400 + ts.Hours * 3600 + ts.Minutes * 60 + ts.Seconds; 
            return dateDiff; 
        } 


        /// <summary> 
        /// 日期比较 
        /// </summary> 
        /// <param name="today">当前日期</param> 
        /// <param name="writeDate">输入日期</param> 
        /// <param name="n">比较天数</param> 
        /// <returns>大于天数返回true,小于返回false</returns> 
        public static bool CompareDate(string today, string writeDate, int n) 
        { 
            DateTime Today = Convert.ToDateTime(today); 
            DateTime WriteDate = Convert.ToDateTime(writeDate); 
            WriteDate = WriteDate.AddDays(n); 
            if (Today >= WriteDate) 
                return false; 
            else 
                return true; 
        } 





    } 
} 



小鱼的淘宝店铺-多多支持哇

C# DES 加密/解密类库,支持文件和中文/UNICODE字符,返回BASE64编码字符串

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)
今天,看到网友咨询DES加密的事,就写了下面的类库,sharing 一下,欢迎多交流

代码 复制 - 运行

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.IO; 
using System.Security; 
using System.Security.Cryptography; 

/*---------------------------------------------- 
 *  DES加密、解密类库,字符串加密结果使用BASE64编码返回,支持文件的加密和解密 
 *  作者: 三角猫/DeltaCat 
 *  网址: http://www.zu14.cn 
 *  转载务必保留此信息 
 * --------------------------------------------- 
 */ 

namespace ZU14 
{ 
    public sealed class DES 
    { 
        string iv = "1234的yzo"; 
        string key = "123在yzo"; 

        /// <summary> 
        /// DES加密偏移量,必须是>=8位长的字符串 
        /// </summary> 
        public string IV 
        { 
            get { return iv; } 
            set { iv = value; } 
        } 

        /// <summary> 
        /// DES加密的私钥,必须是8位长的字符串 
        /// </summary> 
        public string Key 
        { 
            get { return key; } 
            set { key = value; } 
        } 

        /// <summary> 
        /// 对字符串进行DES加密 
        /// </summary> 
        /// <param name="sourceString">待加密的字符串</param> 
        /// <returns>加密后的BASE64编码的字符串</returns> 
        public string Encrypt(string sourceString) 
        { 
            byte[] btKey = Encoding.Default.GetBytes(key); 
            byte[] btIV = Encoding.Default.GetBytes(iv); 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
            using (MemoryStream ms = new MemoryStream()) 
            { 
                byte[] inData = Encoding.Default.GetBytes(sourceString); 
                try 
                { 
                    using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)) 
                    { 
                        cs.Write(inData, 0, inData.Length); 
                        cs.FlushFinalBlock(); 
                    } 

                    return Convert.ToBase64String(ms.ToArray()); 
                } 
                catch 
                { 
                    throw; 
                } 
            } 
        } 

        /// <summary> 
        /// 对DES加密后的字符串进行解密 
        /// </summary> 
        /// <param name="encryptedString">待解密的字符串</param> 
        /// <returns>解密后的字符串</returns> 
        public string Decrypt(string encryptedString) 
        { 
            byte[] btKey = Encoding.Default.GetBytes(key); 
            byte[] btIV = Encoding.Default.GetBytes(iv); 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 

            using (MemoryStream ms = new MemoryStream()) 
            { 
                byte[] inData = Convert.FromBase64String(encryptedString); 
                try 
                { 
                    using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)) 
                    { 
                        cs.Write(inData, 0, inData.Length); 
                        cs.FlushFinalBlock(); 
                    } 

                    return Encoding.Default.GetString(ms.ToArray()); 
                } 
                catch 
                { 
                    throw; 
                } 
            } 
        } 

        /// <summary> 
        /// 对文件内容进行DES加密 
        /// </summary> 
        /// <param name="sourceFile">待加密的文件绝对路径</param> 
        /// <param name="destFile">加密后的文件保存的绝对路径</param> 
        public void EncryptFile(string sourceFile, string destFile) 
        { 
            if (!File.Exists(sourceFile)) throw new FileNotFoundException("指定的文件路径不存在!", sourceFile); 

            byte[] btKey = Encoding.Default.GetBytes(key); 
            byte[] btIV = Encoding.Default.GetBytes(iv); 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
            byte[] btFile = File.ReadAllBytes(sourceFile); 

            using (FileStream fs = new FileStream(destFile, FileMode.Create, FileAccess.Write)) 
            { 
                try 
                { 
                    using (CryptoStream cs = new CryptoStream(fs, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)) 
                    { 
                        cs.Write(btFile, 0, btFile.Length); 
                        cs.FlushFinalBlock(); 
                    } 
                } 
                catch 
                { 
                    throw; 
                } 
                finally 
                { 
                    fs.Close(); 
                } 
            } 
        } 

        /// <summary> 
        /// 对文件内容进行DES加密,加密后覆盖掉原来的文件 
        /// </summary> 
        /// <param name="sourceFile">待加密的文件的绝对路径</param> 
        public void EncryptFile(string sourceFile) 
        { 
            EncryptFile(sourceFile, sourceFile); 
        } 

        /// <summary> 
        /// 对文件内容进行DES解密 
        /// </summary> 
        /// <param name="sourceFile">待解密的文件绝对路径</param> 
        /// <param name="destFile">解密后的文件保存的绝对路径</param> 
        public void DecryptFile(string sourceFile, string destFile) 
        { 
            if (!File.Exists(sourceFile)) throw new FileNotFoundException("指定的文件路径不存在!", sourceFile); 

            byte[] btKey = Encoding.Default.GetBytes(key); 
            byte[] btIV = Encoding.Default.GetBytes(iv); 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
            byte[] btFile = File.ReadAllBytes(sourceFile); 

            using (FileStream fs = new FileStream(destFile, FileMode.Create, FileAccess.Write)) 
            { 
                try 
                { 
                    using (CryptoStream cs = new CryptoStream(fs, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)) 
                    { 
                        cs.Write(btFile, 0, btFile.Length); 
                        cs.FlushFinalBlock(); 
                    } 
                } 
                catch 
                { 
                    throw; 
                } 
                finally 
                { 
                    fs.Close(); 
                } 
            } 
        } 

        /// <summary> 
        /// 对文件内容进行DES解密,加密后覆盖掉原来的文件 
        /// </summary> 
        /// <param name="sourceFile">待解密的文件的绝对路径</param> 
        public void DecryptFile(string sourceFile) 
        { 
            DecryptFile(sourceFile, sourceFile); 
        } 
    } 
} 


使用的例子: 

ZU14.DES des = new ZU14.DES(); 
des.IV = "abcd哈哈笑"; 
des.Key = "必须八位"; 

string es = des.Encrypt("在"); 
Console.WriteLine(es); 
Console.Write(des.Decrypt(es)); 

des.EncryptFile(@"d:\a.txt", @"d:\b.txt"); 
des.DecryptFile(@"d:\b.txt"); 

Console.ReadKey(true);  



OK了。
http://zu14.javaeye.com/blog/779871
本帖最后由 张小鱼 于 2011-02-09 10:05 编辑
小鱼的淘宝店铺-多多支持哇

C#使用网易免费企业邮箱(域名邮箱)进行邮件发送!

视频在线上传+队列转换FLV+水印+捉图+修复+获时+转3GP(API语言不限,开视频站必备!)

琢磨了一整天,一直没有找到之前写的邮件发送方法为什么不能使用smtp.ym.163.com发送邮件的原因,偶然的一个操作竟然可以了,晕啊,发出来大家共享一下。该功能适用于心里有数法律咨询服务网邮件收发使用!
代码如下:
/// <summary>
       /// 邮件发送方法
       /// </summary>
       /// <param name="email">email地址</param>
       /// <param name="subject">邮件标题</param>
       /// <param name="content">邮件内容</param>
       /// <returns></returns>
       public static bool SendEmail(string email, string subject, string content)
       {
           string fromSMTP = System.Configuration.ConfigurationManager.AppSettings["FromSMTP"];        //邮件服务器
           string fromEmail = System.Configuration.ConfigurationManager.AppSettings["FromEmail"];      //发送方邮件地址
           string fromEmailPwd = System.Configuration.ConfigurationManager.AppSettings["FromEmailPwd"];//发送方邮件地址密码
           string fromEmailName = System.Configuration.ConfigurationManager.AppSettings["FromName"];   //发送方称呼
           //新建一个MailMessage对象
           MailMessage aMessage = new MailMessage(fromEmail, email, subject, content);
           aMessage.BodyEncoding = Encoding.GetEncoding("gb2312");
           aMessage.IsBodyHtml = true;
           aMessage.Priority = MailPriority.High;
           aMessage.ReplyTo = new MailAddress(fromEmail, fromEmailName); //邮件回复地址
           SmtpClient smtp = new SmtpClient();
           smtp.Host = fromSMTP;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
           smtp.EnableSsl = false;
           smtp.Credentials = new NetworkCredential(fromEmail, fromEmailPwd); //发邮件的EMIAL和密码
           smtp.Port = 25;
           try
           {
               smtp.Send(aMessage);
               return true;
           }
           catch (Exception ex)
           {
               //return false;
               throw ex;
           }
       }
之前主要是少了smtp.DeliveryMethod = SmtpDeliveryMethod.Network;这句代码代码,没有这句代码smtp.163.com可以正常收发,但smtp.ym.163.com就不可以了,仅此区别,与大家分享!
另外,今天还发现了个问题,第一次发送邮件时总是接收不到,刷新页面后邮件才真正发送出去并接收到了。问题在于,我本机装了诺顿杀毒软件,默认开启的对电子邮件发送自动保护功能,导致每第一次都发送不成功,关闭后就ok了,呵呵!
小鱼的淘宝店铺-多多支持哇