Example #1
0
 public static bool InIPArray(string ip, string[] ipArray)
 {
     if (!string.IsNullOrEmpty(ip) && Validate.IsIP(ip))
     {
         string[] array = TextUtility.SplitStrArray(ip, ".");
         for (int i = 0; i < ipArray.Length; i++)
         {
             string[] array2 = TextUtility.SplitStrArray(ipArray[i], ".");
             int      num    = 0;
             for (int j = 0; j < array2.Length; j++)
             {
                 if (array2[j] == "*")
                 {
                     return(true);
                 }
                 if (array.Length <= j || array2[j] != array[j])
                 {
                     break;
                 }
                 num++;
             }
             if (num == 4)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
 public static bool InArray(string matchStr, string originalStr, string separator)
 {
     string[] array = TextUtility.SplitStrArray(originalStr, separator);
     for (int i = 0; i < array.Length; i++)
     {
         if (matchStr == array[i])
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
        public static string[] SearchUTF8File(string directory)
        {
            StringBuilder builder = new StringBuilder();

            FileInfo[] files = new DirectoryInfo(directory).GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Extension.ToLower().Equals(".htm"))
                {
                    FileStream sbInputStream = new FileStream(files[i].FullName, FileMode.Open, FileAccess.Read);
                    bool       flag          = IsUTF8(sbInputStream);
                    sbInputStream.Close();
                    if (!flag)
                    {
                        builder.Append(files[i].FullName);
                        builder.Append("\r\n");
                    }
                }
            }
            return(TextUtility.SplitStrArray(builder.ToString(), "\r\n"));
        }
Example #4
0
 public static bool InArray(string matchStr, string strArray, string separator, bool ignoreCase)
 {
     return(TextUtility.InArray(matchStr, TextUtility.SplitStrArray(strArray, separator), ignoreCase));
 }
Example #5
0
        public static string[] UploadFile(HttpPostedFile upfile, string limitType, int limitSize, bool autoName, string autoFilename, string savepath)
        {
            string str6;
            bool   flag;

            string[] strArray  = new string[5];
            string[] strArray2 = null;
            if (!string.IsNullOrEmpty(limitType))
            {
                strArray2 = TextUtility.SplitStrArray(limitType, ",");
            }
            int    contentLength = upfile.ContentLength;
            string fileName      = upfile.FileName;
            string originalStr   = Path.GetFileName(fileName);

            switch (originalStr)
            {
            case null:
            case "":
                strArray[0] = "无文件";
                strArray[1] = "";
                strArray[2] = "";
                strArray[3] = "";
                strArray[4] = "<span style='color:red;'>失败</span>";
                return(strArray);

            default:
            {
                string   contentType        = upfile.ContentType;
                string[] strArray3          = TextUtility.SplitStrArray(originalStr, ".");
                string   strA               = strArray3[strArray3.Length - 1];
                int      length             = (originalStr.Length - strA.Length) - 1;
                string   dateTimeLongString = "";
                if (autoName)
                {
                    dateTimeLongString = TextUtility.GetDateTimeLongString();
                }
                else if (TextUtility.EmptyTrimOrNull(autoFilename))
                {
                    dateTimeLongString = originalStr.Substring(0, length);
                }
                else
                {
                    dateTimeLongString = autoFilename;
                }
                str6        = dateTimeLongString + "." + strA;
                strArray[0] = fileName;
                strArray[1] = str6;
                strArray[2] = contentType;
                strArray[3] = contentLength.ToString();
                flag        = false;
                if ((limitSize <= contentLength) && (limitSize != 0))
                {
                    strArray[4] = "<span style='color:red;'>失败</span>,上传文件过大";
                    flag        = false;
                }
                else if (strArray2 != null)
                {
                    for (int i = 0; i <= (strArray2.Length - 1); i++)
                    {
                        if (string.Compare(strA, strArray2[i].ToString(), true) == 0)
                        {
                            flag = true;
                            break;
                        }
                        strArray[4] = "<span style='color:red;'>失败</span>,文件类型不允许上传";
                        flag        = false;
                    }
                }
                else
                {
                    flag = true;
                }
                break;
            }
            }
            if (flag)
            {
                try
                {
                    string file = savepath + str6;
                    FileManager.WriteFile(file, "临时文件");
                    upfile.SaveAs(file);
                    strArray[4] = "成功";
                }
                catch (Exception exception)
                {
                    strArray[4] = "<span style='color:red;'>失败</span><!-- " + exception.Message + " -->";
                }
            }
            return(strArray);
        }