コード例 #1
0
ファイル: Net.cs プロジェクト: nkYellOw/test
 public void DownloadFile(string link, string filePath)
 {
     using (var wc = new CookieWebClient())
     {
         // if (!System.IO.File.Exists(filePath))
         // {
         wc.DownloadFile(link, filePath);
         //}
     }
 }
コード例 #2
0
ファイル: Server.cs プロジェクト: RowShare/developers
        public string DownloadCall(ServerCallParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using (var client = new CookieWebClient())
            {
                if (Cookie != null)
                {
                    client.Cookies.Add(new Cookie(CookieName, Cookie, "/", new Uri(Url).Host));
                }


                string url = parameters.Api;
                if (parameters.Api != null && !parameters.Api.StartsWith("/"))
                {
                    url = "/" + url;
                }

                var uri =
                    new EditableUri(Url + url);
                if (!string.IsNullOrWhiteSpace(parameters.Format))
                {
                    uri.Parameters["f"] = parameters.Format;
                }

                if (parameters.Lcid != 0)
                {
                    uri.Parameters["l"] = parameters.Lcid;
                }

                try
                {
                    var filePath = LongPath.GetTempFileName();
                    client.DownloadFile(uri.ToString(), filePath);
                    return(filePath);
                }
                catch (WebException e)
                {
                    if (ShowMessageBoxOnError)
                    {
                        var eb = new ErrorBox(e, e.GetErrorText(null));
                        eb.ShowDialog();
                    }
                    throw;
                }
            }
        }