当前位置: 首页>>代码示例>>C#>>正文


C# System.Net.WebClient.DownloadData方法代码示例

本文整理汇总了C#中System.Net.WebClient.DownloadData方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.DownloadData方法的具体用法?C# System.Net.WebClient.DownloadData怎么用?C# System.Net.WebClient.DownloadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了System.Net.WebClient.DownloadData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            String pageIDString = context.Request.QueryString["PageID"] as String;
            if (pageIDString == null) return;

            String heightString = context.Request.QueryString["h"] as String;
            String widthString = context.Request.QueryString["w"] as String;
            int height;
            int width;
            if (!Int32.TryParse(heightString, out height)) height = 300;
            if (!Int32.TryParse(widthString, out width)) width = 200;

            int pageID;
            if (Int32.TryParse(pageIDString, out pageID))
            {
                BHLProvider provider = new BHLProvider();
                PageSummaryView ps = provider.PageSummarySelectByPageId(pageID);
                String imageUrl = String.Empty;

                if (ps.ExternalURL == null)
                {
                    String cat = (ps.WebVirtualDirectory == String.Empty) ? "Researchimages" : ps.WebVirtualDirectory;
                    String item = ps.MARCBibID + "/" + ps.BarCode + "/jp2/" + ps.FileNamePrefix + ".jp2";
                    imageUrl = String.Format("http://images.mobot.org/ImageWeb/GetImage.aspx?cat={0}&item={1}&wid=" + width.ToString() + "&hei= " + height.ToString() + "&rgn=0,0,1,1&method=scale", cat, item);
                }
                else
                {
                    imageUrl = ps.ExternalURL;
                }

                System.Net.WebClient client = new System.Net.WebClient();
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(client.DownloadData(imageUrl));
            }
        }
开发者ID:hoangbktech,项目名称:bhl-bits,代码行数:35,代码来源:GetPageThumb.ashx.cs

示例2: getCoordinates

        public static decimal[] getCoordinates(string address1, string address2,
            string city, string state, string zipcode, string appId)
        {
            string retVal;
            decimal[] coordinates = new decimal[2];

            System.Net.WebClient webClient = new System.Net.WebClient();
            string request = "http://where.yahooapis.com/geocode?location="
                + address1 + "+" + address2 + "+" + city + "+" + state + "+" + zipcode
                + "&" + appId;

            byte[] responseXML;
            try
            {
                responseXML = webClient.DownloadData(request);
                System.Text.UTF8Encoding objUTF8 = new System.Text.UTF8Encoding();
                retVal = objUTF8.GetString(responseXML) + "\n";
            }
            catch (System.Exception ex)
            {
                retVal = ex.Message;
            }

            // parse the return values
            XmlDocument xml = new XmlDocument();
            xml.LoadXml(retVal);
            XmlNode ndLatitude = xml.SelectSingleNode("//latitude");
            XmlNode ndLongitude = xml.SelectSingleNode("//longitude");

            coordinates[0] = Convert.ToDecimal(ndLatitude.InnerText);
            coordinates[1] = Convert.ToDecimal(ndLongitude.InnerText);

            return coordinates;
        }
开发者ID:ManigandanS,项目名称:Disaster-Management-Communication-System,代码行数:34,代码来源:GeoLocation.cs

示例3: getXMLDocument

        private string getXMLDocument(string url)
        {
            // Grab the body of xml document from its source

            System.Net.WebClient wc = new System.Net.WebClient();
            byte[] webData = wc.DownloadData(url);

            // Get the downloaded data into a form suitable for XML processing

            char[] charData = new char[webData.Length];
            for (int i = 0; i < charData.Length; i++)
            {
                charData[i] = (char)webData[i];
            }

            string xmlStr = new String(charData);

            // Clean up the document (first "<" and last ">" and everything in between)

            int start = xmlStr.IndexOf("<", 0, xmlStr.Length - 1);
            int length = xmlStr.LastIndexOf(">") - start + 1;

            // Return only the XML document parts
            return xmlStr.Substring(start, length);
        }
开发者ID:juyingnan,项目名称:VS,代码行数:25,代码来源:Program.cs

示例4: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            // 以下を追加
            this.btnDownload.Click += (sender, e) =>
            {
                var client = new System.Net.WebClient();
                byte[] buffer = client.DownloadData("http://k-db.com/?p=all&download=csv");
                string str = Encoding.Default.GetString(buffer);
                string[] rows = str.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                // 1行目をラベルに表示
                this.lblTitle.Content = rows[0];
                // 2行目以下はカンマ区切りから文字列の配列に変換しておく
                List<string[]> list = new List<string[]>();
                rows.ToList().ForEach(row => list.Add(row.Split(new char[] { ',' })));
                // ヘッダの作成(データバインド用の設計)
                GridView view = new GridView();
                list.First().Select((item, cnt) => new { Count = cnt, Item = item }).ToList().ForEach(header =>
                {
                    view.Columns.Add(
                        new GridViewColumn()
                        {
                            Header = header.Item,
                            DisplayMemberBinding = new Binding(string.Format("[{0}]", header.Count))
                        });
                });
                // これらをリストビューに設定
                lvStockList.View = view;
                lvStockList.ItemsSource = list.Skip(1);
            };
        }
开发者ID:kudakas,项目名称:KabutradeTool1,代码行数:32,代码来源:MainWindow.xaml.cs

示例5: GetBinaryFromURL

        internal byte[] GetBinaryFromURL(string URL)
        {
            LogProvider.LogMessage(string.Format("Url.GetBinaryFromURL - '{0}'", URL));
            string cacheKey = string.Format("GetBinaryFromURL_{0}", URL);

            var cached = CacheProvider.Get<byte[]>(cacheKey);
            if (cached != null)
            {
                LogProvider.LogMessage("Url.GetBinaryFromURL  :  Returning cached result");
                return cached;
            }
            LogProvider.LogMessage("Url.GetBinaryFromURL  :  Cached result unavailable, fetching url content");

            var webClient = new System.Net.WebClient();
            byte[] result;
            try
            {
                result = webClient.DownloadData(URL);
            }
            catch (Exception error)
            {
                if (LogProvider.HandleAndReturnIfToThrowError(error))
                    throw;
                return null;
            }

            CacheProvider.Set(result, cacheKey);
            return result;
        }
开发者ID:bradfordcogswell,项目名称:GitHubSharp,代码行数:29,代码来源:Url.cs

示例6: ResizeImage

        public override bool ResizeImage(string sourceImagePath, Size newSize)
        {



            var fileurl = this._imageFile.GetImageUrl(sourceImagePath);


            System.Net.WebClient net = new System.Net.WebClient();





            var file = net.DownloadData(fileurl);

            var newstream = this._imageFile.ResizeImage(file, newSize.Width, newSize.Height);

            this._imageFile.UpdateImageFile(newstream, sourceImagePath);


            var model = DB.GetModelByHash(sourceImagePath);
            model.Size = (int)newstream.Length;
            var size = Dev.Comm.ImageHelper.GetImageSize(newstream);
            model.Width = size.Width;
            model.Height = size.Height;
            DB.UpdateModel(model);

            return true;
        }
开发者ID:zbw911,项目名称:Dev.elFinder.Connector.MsSql,代码行数:30,代码来源:FileServerImageEditorService.cs

示例7: Go

        public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats)
        {
            System.Net.WebClient wc = new System.Net.WebClient();
            try
            {
                byte[] r = wc.DownloadData(this.RSS.URL);
                if ((r == null) || (r.Length == 0))
                {
                    this.Error = true;
                    this.ErrorText = "No data downloaded";
                    this.Done = true;
                    return false;
                }

                string saveTemp = Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + settings.FilenameFriendly(this.RSS.Title);
                if (new FileInfo(saveTemp).Extension.ToLower() != "torrent")
                    saveTemp += ".torrent";
                File.WriteAllBytes(saveTemp, r);

                System.Diagnostics.Process.Start(settings.uTorrentPath, "/directory \"" + (new FileInfo(this.TheFileNoExt).Directory.FullName) + "\" \"" + saveTemp + "\"");

                this.Done = true;
                return true;
            }
            catch (Exception e)
            {
                this.ErrorText = e.Message;
                this.Error = true;
                this.Done = true;
                return false;
            }
        }
开发者ID:madams74,项目名称:tvrename,代码行数:32,代码来源:ActionRSS.cs

示例8: readOCR

        public static string readOCR (Uri ocr_url) {
            AzureSearchServiceController checkUrl = new AzureSearchServiceController();
            string ocrPrevText = "";
            if (checkUrl.RemoteFileExists(ocr_url.ToString()))
            {
                

                System.Net.WebClient wc = new System.Net.WebClient();
                byte[] raw = wc.DownloadData(ocr_url);
                string webData = System.Text.Encoding.UTF8.GetString(raw);

                string[] ocrSplit = webData.Split(' ');

                for (int i = 0; i < 300; i++)
                {
                    ocrPrevText += ocrSplit[i];
                    ocrPrevText += " ";

                }

                return ocrPrevText;

            }
            else
            {

                ocrPrevText ="Unfortunately OCR is not available for this document";

            } return ocrPrevText;
           
        }
开发者ID:BL-publicdomain,项目名称:blpublicdomain,代码行数:31,代码来源:ItemPageController.cs

示例9: EncryptionButtonInValidateCard_Click

        protected void EncryptionButtonInValidateCard_Click(object sender, EventArgs e)
        {
            Uri baseUri = new Uri("http://webstrar49.fulton.asu.edu/page3/Service1.svc");
            UriTemplate myTemplate = new UriTemplate("encrypt?plainText={plainText}");

            String plainText = PlainText_TextBox1.Text;
            Uri completeUri = myTemplate.BindByPosition(baseUri, plainText);

            System.Net.WebClient webClient = new System.Net.WebClient();
            byte[] content = webClient.DownloadData(completeUri);

            //EncryptionService.Service1Client encryptionClient = new EncryptionService.Service1Client();
            // String cipher=encryptionClient.encrypt(plainText);

            String contentinString = Encoding.UTF8.GetString(content, 0, content.Length);

            String pattern = @"(?<=\>)(.*?)(?=\<)";
            Regex r = new Regex(pattern);
            Match m = r.Match(contentinString);

            String cipher = "";
            if (m.Success)
            {
                cipher = m.Groups[1].ToString();
            }

            cipherTextBox.Enabled = true;
            cipherTextBox.Text = cipher;
            cipherTextBox.Enabled = false;
        }
开发者ID:jvutukur,项目名称:DistributedSoftwareDevelopmentProject,代码行数:30,代码来源:Payment.aspx.cs

示例10: GetDonationDriveFromWeb

 public static string GetDonationDriveFromWeb()
 {
     string sourceUrl = ConfigurationManager.AppSettings["JsDataSourceUrl"];
     using (var wc = new System.Net.WebClient())
     using (MemoryStream stream = new MemoryStream(wc.DownloadData(sourceUrl)))
         return Encoding.UTF8.GetString(stream.ToArray());
 }
开发者ID:ray023,项目名称:lifesouth-blood-mobile-solution,代码行数:7,代码来源:WebHelper.cs

示例11: Download

 public static Stream Download(this Uri url)
 {
     using (var webClient = new System.Net.WebClient())
     {
         var data = webClient.DownloadData(url);
         return new MemoryStream(data);
     }
 }
开发者ID:joshcodes,项目名称:JoshCodes.Core,代码行数:8,代码来源:GenericExtensions.cs

示例12: Return

        public ActionResult Return(string rid, string SPListId, string documentName, string SPSource, string SPListURLDir)
        {
            // Get the tokens
            string spAppToken = Request.Cookies["SPAppToken"].Value;
            string spHostURL = Request.Cookies["SPHostURL"].Value;

            using (var client = new DocumentEndPointClient())
            {
                var getStatusResponse = client.getStatus(new getstatusrequest
                {
                    password = PASSWORD,
                    service = SERVICE,
                    requestid = new string[] { rid }
                });

                // If there's no signature result available, we assume it's been cancelled
                // and just send the user back to the document list he/she came from
                if (getStatusResponse.First().documentstatus == null)
                {
                    return Redirect(SPSource);
                }

                // Otherwise, we get the URI to the SDO (signed document object)
                string resultUri = getStatusResponse.First().documentstatus.First().resulturi;

                // Let's just use an old school HTTP WebClient with Basic authentication
                // to download the signed document from Signicat Session Data Storage
                byte[] sdo;
                string contentType;
                using (var webClient = new System.Net.WebClient())
                {
                    webClient.Credentials = new System.Net.NetworkCredential(SERVICE, PASSWORD);
                    sdo = webClient.DownloadData(resultUri);
                    contentType = webClient.ResponseHeaders["Content-Type"];
                }

                // Now, let's upload it to the same document list as the original
                SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(spAppToken, Request.Url.Authority);
                string accessToken = TokenHelper.GetAccessToken(contextToken, new Uri(spHostURL).Authority).AccessToken;
                using (var clientContext = TokenHelper.GetClientContextWithAccessToken(spHostURL.ToString(), accessToken))
                {
                    if (clientContext != null)
                    {
                        List list = clientContext.Web.Lists.GetById(Guid.Parse(SPListId));
                        var fileCreationInformation = new FileCreationInformation
                        {
                            Content = sdo,
                            Overwrite = true,
                            Url = spHostURL + SPListURLDir + "/" + documentName + " - SIGNED" + GetFileExtensionForContentType(contentType)
                        };
                        var uploadFile = list.RootFolder.Files.Add(fileCreationInformation);
                        uploadFile.ListItemAllFields.Update();
                        clientContext.ExecuteQuery();
                    }
                }
            }
            return Redirect(SPSource);
        }
开发者ID:maralm,项目名称:add-in-for-office365,代码行数:58,代码来源:HomeController.cs

示例13: getImageAsBitmap

 public static Bitmap getImageAsBitmap(this Uri uri)
 {
     var webClient = new System.Net.WebClient();
     var imageBytes = webClient.DownloadData(uri);
     "image size :{0}".info(imageBytes.size());
     var memoryStream = new MemoryStream(imageBytes);
     var bitmap = new Bitmap(memoryStream);
     return bitmap;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:9,代码来源:Web_ExtensionMethods.cs

示例14: ToStream

        public static Stream ToStream(this Uri url)
        {
            byte[] imageData = null;

            using (var wc = new System.Net.WebClient())
                imageData = wc.DownloadData(url);

            return new MemoryStream(imageData);
        }
开发者ID:joshcodes,项目名称:JoshCodes.Web,代码行数:9,代码来源:UriExtensions.cs

示例15: GetMenu

 public static string GetMenu(string accessToken)
 {
     using (var wc = new System.Net.WebClient())
     {
         var url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + accessToken;
         var res = wc.DownloadData(url);
         return Utities.GetStringFromBytes(res);
     }
 }
开发者ID:sirithink,项目名称:WeiXin-3,代码行数:9,代码来源:Utities.cs


注:本文中的System.Net.WebClient.DownloadData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。