コード例 #1
0
        private string downloadFile(ArticlePDF from)
        {
            // string fileOutDirectory = from.FilePath; //string.Format("{0}{1}", OutputDirectory, from.FilePath);
            string sDirecorty = Path.GetDirectoryName(from.FilePath);

            if (!Directory.Exists(sDirecorty))
            {
                Directory.CreateDirectory(sDirecorty);
            }

            using (WebClient wc = new WebClient())
            {
                wc.DownloadFile(from.Url, from.FilePath);

                return(string.Format("Download: {0} URL: {1}", from.FilePath, from.Url));
            }

            /*
             * Uri address = new Uri(from.Url);
             *
             * ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
             * ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
             *
             * using (WebClient webClient = new WebClient())
             * {
             *  var stream = webClient.OpenRead(address);
             *  using (StreamReader sr = new StreamReader(stream))
             *  {
             *      var page = sr.ReadToEnd();
             *  }
             * }
             * return "";*/
        }
コード例 #2
0
        private void moveArticle(ArticlePDF from, ArticlePDF to)
        {
            string sFromPath = from.FilePath;
            string sToPath   = to.FilePath;

            if (File.Exists(sToPath))
            {
                sToPath = string.Format("{0}}_Copy{1}", sToPath, DateTime.Now.ToString("dd_mm_yyyy_HH_MM_ss"));
            }

            File.Move(sFromPath, sToPath);
        }