public async Task<ActionResult> DownloadImage(string mediaId) { string accessToken = string.Empty; string file = string.Empty; string content = string.Empty; string strpath = string.Empty; string savepath = string.Empty; string stUrl = string.Empty; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(stUrl); req.Method = "GET"; await new Task(() => { HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse(); strpath = myResponse.ResponseUri.ToString(); WebClient mywebclient = new WebClient(); savepath = Server.MapPath("~/Upload/UploadImage") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg"; ///C:inetpub\wwwroot\Upload\UploadImage try { mywebclient.DownloadFile(strpath, savepath); file = savepath.Substring(18); } catch (Exception ex) { savepath = ex.ToString(); } }); return Json(new { Link = file }, JsonRequestBehavior.AllowGet); }
