コード例 #1
0
        private string SaveYuanFile(System.Text.RegularExpressions.Match m)
        {
            string str   = "";
            string value = m.Value;
            string str1  = "";

            str1 = value.Substring(5);
            str1 = str1.Substring(0, str1.IndexOf("\""));
            if (!(new Regex("^http://*")).Match(str1).Success)
            {
                str = value;
            }
            else
            {
                value = value.Substring(5);
                value = value.Substring(0, value.IndexOf("\""));
                string str2 = ConfigurationManager.AppSettings["yuanimg"].ToString();
                string str3 = value;
                string str4 = str3.Substring(str3.LastIndexOf("."));
                string str5 = string.Concat(str2, FileOperate.GetFileName(), str4);
                if (File.Exists(HttpContext.Current.Request.MapPath(str5)))
                {
                    File.Delete(HttpContext.Current.Request.MapPath(str5));
                }
                this.GetHttpFile(value, HttpContext.Current.Request.MapPath(str5));
                str = string.Concat("src=\"/", str5.Replace("~/", ""), "\"");
            }
            return(str);
        }
コード例 #2
0
        public static string IniReadValue(string section, string key, string path)
        {
            StringBuilder stringBuilder = new StringBuilder(255);

            FileOperate.GetPrivateProfileString(section, key, "", stringBuilder, 255, path);
            return(stringBuilder.ToString());
        }
コード例 #3
0
        public static ArrayList ReadSections(string path)
        {
            byte[]    numArray = new byte[65535];
            int       privateProfileSectionNamesA = FileOperate.GetPrivateProfileSectionNamesA(numArray, numArray.GetUpperBound(0), path);
            ArrayList arrayLists = new ArrayList();

            if (privateProfileSectionNamesA > 0)
            {
                int i   = 0;
                int num = 0;
                for (i = 0; i < privateProfileSectionNamesA; i++)
                {
                    if (numArray[i] == 0)
                    {
                        string str = Encoding.Default.GetString(numArray, num, i - num).Trim();
                        num = i + 1;
                        if (str != "")
                        {
                            arrayLists.Add(str);
                        }
                    }
                }
            }
            return(arrayLists);
        }
コード例 #4
0
        private static Hashtable getAllFies(string filesdirectorypath, out int dirnamelength)
        {
            Hashtable     hashtables    = new Hashtable();
            DirectoryInfo directoryInfo = new DirectoryInfo(filesdirectorypath);

            if (!directoryInfo.Exists)
            {
                throw new FileNotFoundException(string.Concat("目录:", directoryInfo.FullName, "没有找到!"));
            }
            dirnamelength = directoryInfo.Name.Length;
            FileOperate.getAllDirFiles(directoryInfo, hashtables);
            FileOperate.getAllDirsFiles(directoryInfo.GetDirectories(), hashtables);
            return(hashtables);
        }
コード例 #5
0
 private static void getAllDirsFiles(DirectoryInfo[] dirs, Hashtable filesList)
 {
     DirectoryInfo[] directoryInfoArray = dirs;
     for (int i = 0; i < (int)directoryInfoArray.Length; i++)
     {
         DirectoryInfo directoryInfo = directoryInfoArray[i];
         FileInfo[]    files         = directoryInfo.GetFiles("*.*");
         for (int j = 0; j < (int)files.Length; j++)
         {
             FileInfo fileInfo = files[j];
             filesList.Add(fileInfo.FullName, fileInfo.LastWriteTime);
         }
         FileOperate.getAllDirsFiles(directoryInfo.GetDirectories(), filesList);
     }
 }
コード例 #6
0
        private static string GetChartset(string url)
        {
            string hTML  = FileOperate.getHTML(url);
            Regex  regex = new Regex("charset\\b\\s*=\\s*(?<charset>[^\"]*)");
            string str   = null;

            str = (!regex.IsMatch(hTML) ? Encoding.Default.EncodingName : regex.Match(hTML).Groups["charset"].Value);
            if (str.ToLower().Contains("gb2312"))
            {
                str = "gb2312";
            }
            if (str.ToLower().Contains("utf-8"))
            {
                str = "utf-8";
            }
            return(str);
        }
コード例 #7
0
        public static string UpLoadFile(FileUpload fileupload, string Folders)
        {
            string fileName = fileupload.PostedFile.FileName;

            if (fileName == null || fileName.Equals(""))
            {
                return("");
            }
            string str  = fileName.Substring(fileName.LastIndexOf("."));
            string str1 = string.Concat(Folders, FileOperate.GetFileName(), str);
            string str2 = HttpContext.Current.Server.MapPath(str1);

            if (File.Exists(str2))
            {
                File.Delete(str2);
            }
            fileupload.PostedFile.SaveAs(str2);
            return(str1);
        }
コード例 #8
0
 public static void IniWriteValue(string section, string key, string iValue, string path)
 {
     FileOperate.WritePrivateProfileString(section, key, iValue, path);
 }
コード例 #9
0
 public static byte[] IniReadValues(string section, string key, string path)
 {
     byte[] numArray = new byte[255];
     FileOperate.GetPrivateProfileString(section, key, "", numArray, 255, path);
     return(numArray);
 }
コード例 #10
0
        public static string GetRemotUrl(string url, int Type)
        {
            string str   = url.Trim();
            string empty = string.Empty;
            string end   = string.Empty;

            try
            {
                HttpWebResponse response        = (HttpWebResponse)((HttpWebRequest)WebRequest.Create(str)).GetResponse();
                string          contentEncoding = response.ContentEncoding;
                Stream          responseStream  = response.GetResponseStream();
                Encoding        encoding        = Encoding.GetEncoding(FileOperate.GetChartset(str));
                if (contentEncoding.ToLower() != "gzip")
                {
                    using (StreamReader streamReader = new StreamReader(responseStream, encoding))
                    {
                        end = streamReader.ReadToEnd();
                    }
                }
                else
                {
                    using (StreamReader streamReader1 = new StreamReader(new GZipStream(responseStream, CompressionMode.Decompress), encoding))
                    {
                        end = streamReader1.ReadToEnd();
                    }
                }
                switch (Type)
                {
                case 1:
                {
                    empty = end;
                    break;
                }

                case 2:
                {
                    empty = FileOperate.wipeScript(end);
                    break;
                }

                case 3:
                {
                    empty = FileOperate.ClearHTML(end);
                    break;
                }

                case 4:
                {
                    empty = FileOperate.getImages(str, end);
                    break;
                }

                case 5:
                {
                    empty = FileOperate.getLink(str, end);
                    break;
                }
                }
            }
            catch
            {
                empty = "Error";
            }
            return(empty);
        }
コード例 #11
0
 public static void SetXmlValue(string Target, string attributes, string TargetValue, string xmlPath)
 {
     FileOperate.SetXmlTargetValue(Target, attributes, TargetValue, xmlPath);
 }