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


C# WebClient.OpenWriteAsync方法代码示例

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


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

示例1: UploadFile

 private void UploadFile(string fileName, Stream data)
 {
     UriBuilder ub = new UriBuilder("/Image/UploadFile");
     ub.Query = string.Format("filename={0}", fileName);
     WebClient c = new WebClient();
     c.OpenWriteCompleted += (sender, e) =>
         {
             PushData(data, e.Result);
             e.Result.Close();
             data.Close();
         };
     c.OpenWriteAsync(ub.Uri);
 }
开发者ID:paulallies,项目名称:NMPIB,代码行数:13,代码来源:MainPage.xaml.cs

示例2: button2_Click

        protected void button2_Click(object sender, EventArgs e)
        {
            //FileUpload fi = FileUpload1;

            //byte[] bt = fi.FileBytes;//获取文件的Byte[]
            //ms = new MemoryStream(bt);//用Byte[],实例化ms

            UriBuilder url = new UriBuilder("http://localhost:81/test/uploadfile.ashx");//上传路径
            url.Query = string.Format("filename={0}", Path.GetFileName("ttttt.tt"));//上传url参数
            WebClient wc = new WebClient();
            wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);//委托异步上传事件
            wc.OpenWriteAsync(url.Uri);//开始异步上传
        }
开发者ID:kissmettprj,项目名称:col,代码行数:13,代码来源:Form1.cs

示例3: UploadFiles

        private void UploadFiles(MyFileInfo mfi, System.IO.FileStream data)
        {
            UriBuilder ub = new UriBuilder("http://localhost:3793/receiver.ashx");
            ub.Query = string.Format("filename={0}&name={1}&address={2}&email={3}&golfid={4}", mfi.Name, fixText(txtName.Text), fixText(txtAdress.Text), fixText(txtEmail.Text), fixText(txtGolfID.Text));
            //ub.Query = string.Format("filename={0}", mfi.Name);
            WebClient wc = new WebClient();

            wc.OpenWriteCompleted += (sender, e) =>
            {
                PushData(data, e.Result, mfi);
                e.Result.Close();
                data.Close();
                lbl.Text = "Fil(er) uppladdade!";
            };
            wc.OpenWriteAsync(ub.Uri);
        }
开发者ID:Hagser,项目名称:csharp,代码行数:16,代码来源:MainPage.xaml.cs

示例4: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Dispatcher.BeginInvoke(() =>
                {
                    FrameBorder.Visibility = Visibility.Collapsed;
                    ResultBorder.Visibility = Visibility.Visible;
                });

            Uri serviceUri = new Uri(Defines.BaseUri + "/services/account/uploadphoto");

            WebClient client = new WebClient();

            client.WriteStreamClosed += new WriteStreamClosedEventHandler((o, args) =>
            {
                loadingTextBlock.Visibility = Visibility.Collapsed;
                resultPanel.Visibility = Visibility.Visible;

                Defines.MainPage.RefreshUserInfo();
            });

            client.OpenWriteCompleted += new OpenWriteCompletedEventHandler((o, args) =>
            {
                WriteableBitmap bmp = new WriteableBitmap(frame.Source as BitmapSource);
                Stream encoded = bmp.ToImage().ToStreamByExtension("png");
                encoded.Seek(0, SeekOrigin.Begin);

                byte[] data = new byte[encoded.Length];
                encoded.Read(data, 0, (int)encoded.Length);
                args.Result.Write(data, 0, (int)data.Length);
                args.Result.Flush();
                args.Result.Close();
            });

            client.OpenWriteAsync(serviceUri, "POST");

            resultPhoto.Source = frame.Source;
        }
开发者ID:retran,项目名称:old-projects-backup,代码行数:37,代码来源:SettingsPhoto.xaml.cs

示例5: SaveImage

 //保存照片
 public void SaveImage()
 {
     DefaultCaputerSource dcs = Application.Current.Resources[DefaultCaputerName] as DefaultCaputerSource;
     if (dcs.CutImage != null)
     {
         IsBusy = true;
         if (tempid == null)
         {
             tempid = System.Guid.NewGuid().ToString();
         }
         byte[] by = Convert.FromBase64String(GetBase64Image(dcs.CutImage));
         Stream sr = new MemoryStream(by);
         WebClient webclient = new WebClient();
         Uri uri = new Uri(Path + "?FileName=" + FileName + "&BlobId=" + tempid + "&EntityName=" + EntityName);
         webclient.OpenWriteCompleted += new OpenWriteCompletedEventHandler(webclient_OpenWriteCompleted);
         webclient.Headers["Content-Type"] = "multipart/form-data";
         webclient.OpenWriteAsync(uri, "POST", sr);
         webclient.WriteStreamClosed += new WriteStreamClosedEventHandler(webclient_WriteStreamClosed);
     }
     else
     {
         MessageBox.Show("请拍照!");
     }
 }
开发者ID:DuBin1988,项目名称:restv2,代码行数:25,代码来源:DefaultCaputerObject.cs

示例6: UploadImage

        private void UploadImage(PhotoResult e)
        {

            //ShowProgress = true;
            byte[] sbytedata = ReadToEnd(e.ChosenPhoto);
            string s = sbytedata.ToString();
            albId = app.albums[app.selectedAlbumIndex].id;
            username = (string)appSettings["myEmail"];
            username = username.Substring(0, username.IndexOf("@"));// Get the username part of the email, without @
            WebClient webClient = new WebClient();
            string auth = "GoogleLogin auth=" + app.auth;
            webClient.Headers[HttpRequestHeader.Authorization] = auth;
            webClient.Headers[HttpRequestHeader.ContentType] = "image/jpeg";
            //webClient.Headers[HttpRequestHeader.ContentLength]=(string) e.ChosenPhoto.Length;
            Uri uri = new Uri(string.Format("https://picasaweb.google.com/data/feed/api/user/{0}/albumid/{1}", username, albId));
            webClient.AllowReadStreamBuffering = true;
            webClient.AllowWriteStreamBuffering = true;
            webClient.OpenWriteCompleted += new OpenWriteCompletedEventHandler(webClient_OpenWriteCompleted);
            webClient.OpenWriteAsync(uri, "POST", sbytedata);
        }
开发者ID:bikila,项目名称:MobiPicasa,代码行数:20,代码来源:PhotoProcess.xaml.cs

示例7: UploadFile

        private void UploadFile(string fileName, FileStream fileStream, Image myImage)
        {
            UriBuilder ub = new UriBuilder(new Uri(App.Current.Host.Source,"../Image/SLUpload"));

            ub.Query = string.Format("filename={0}&Mag_id={1}&Mag_Issue={2}&Shoot={3}&ShootDate={4}&keywords={5}&description={6}&photographer={7}",
                fileName,
                myImage.Magid.ToString(),
                myImage.MagIssue,
                myImage.Shoot,
                myImage.ShootDate.ToString("dd-MMM-yyyy"),
                myImage.keywords,
                myImage.description,
                myImage.photographer
                );

            WebClient c = new WebClient();
            c.OpenWriteCompleted += (sender, e) =>
            {
                PushData(fileStream, e.Result);
                e.Result.Close();
                fileStream.Close();

            };
            c.OpenWriteAsync(ub.Uri);
            c.WriteStreamClosed += (sender, e) =>
            {
                //MessageBox.Show(e.Error.Message);
                HtmlPage.Window.Navigate(new Uri(App.Current.Host.Source, "../"));

            };
        }
开发者ID:paulallies,项目名称:NMPIB,代码行数:31,代码来源:MainPage.xaml.cs

示例8: photoChooserTask_Completed

        void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK)
            {
                return;
            }

            WebClient webClient = new WebClient();
            webClient.OpenWriteCompleted += (s, args) =>
                {
                    using (BinaryReader br = new BinaryReader(e.ChosenPhoto))
                    {
                        using (BinaryWriter bw = new BinaryWriter(args.Result))
                        {
                            long bCount = 0;
                            long fileSize = e.ChosenPhoto.Length;
                            byte[] bytes = new byte[2 * 1024];
                            do
                            {
                                bytes = br.ReadBytes(2 * 1024);
                                bCount += bytes.Length;
                                bw.Write(bytes);

                            } while (bCount < fileSize);
                        }
                    }
                };
            webClient.WriteStreamClosed += webClient_WriteStreamClosed;
            webClient.OpenWriteAsync(new Uri("http://www.cnblogs.com"));
        }
开发者ID:peepo3663,项目名称:WindowsPhone8,代码行数:30,代码来源:MainPage.xaml.cs

示例9: UpLoadFile2

 /// <summary>
 /// WebClient上传文件至服务器
 /// </summary>
 /// <param name="fileNameFullPath">要上传的文件(全路径格式)</param>
 /// <param name="strUrlDirPath">Web服务器文件夹路径</param>
 public void UpLoadFile2( string fileNameFullPath, string saveFileName, string strUrlDirPath)
 {
    
    
      myFileStream = new FileStream(fileNameFullPath, FileMode.Open, FileAccess.Read);
      myBinaryReader = new BinaryReader(myFileStream);
     
     UriBuilder url = new UriBuilder(strUrlDirPath);//上传路径
     url.Query = string.Format("filename={0}", saveFileName);//上传url参数
     WebClient webClient = new WebClient();
     webClient.OpenWriteCompleted+= new OpenWriteCompletedEventHandler(webClient_OpenWriteCompleted);//委托异步上传事件
     webClient.Headers["User-Agent"] = "blah";
     webClient.Credentials = CredentialCache.DefaultCredentials;
     
     webClient.OpenWriteAsync(url.Uri);
 }
开发者ID:s7loves,项目名称:mypowerscgl,代码行数:21,代码来源:DownFileControltwo.cs

示例10: SaveSettings

        public static void SaveSettings()
        {
            JObject j = JObject.FromObject(Store);
            j.Add("FavLists", new JObject());
            if (Store.FavLists != null)
            {
                foreach (FavList favList in Store.FavLists)
                {
                    ((JObject) j["FavLists"]).Add(favList.HtmlName, JArray.FromObject(favList));
                }
            }

            Uri uri = new Uri(String.Format("http://{0}/store.sh", AppSettings.IPAddress));
            WebClient c = new WebClient();
            c.OpenWriteCompleted += (sender, args) =>
                    {
                        if (args.Error != null) return;
                        using (StreamWriter sw = new StreamWriter(args.Result))
                        {
                            sw.Write(j.ToString());
                        }
                    };
            c.OpenWriteAsync(uri);
        }
开发者ID:JQE,项目名称:XK3Y-Remote-Control,代码行数:24,代码来源:DataLoader.cs

示例11: SendFile

        //private void MenuGroupReName_Click(object sender, RoutedEventArgs e)
        //{
        //    StackPanel stk = currentGroupStack;
        //    TextBox tb = stk.FindName("txtGroupName") as TextBox;
        //    TextBlock tblock = stk.FindName("tblkGroupName") as TextBlock;
        //    tblock.Visibility = System.Windows.Visibility.Collapsed;
        //    tb.Visibility = Visibility.Visible;
        //    tb.Focus();
        //}
        //private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
        //{
        //currentGroup =   (sender as  StackPanel).DataContext as tblProjectGroup;
        //currentGroupStack =  sender as StackPanel;
        // treeView1.SelectItem(currentGroup);
        //}
        //private void txtGroupName_LostFocus(object sender, RoutedEventArgs e)
        //{
        //    StackPanel stk = (sender as TextBox).Parent as StackPanel;
        //    TextBox tb = stk.FindName("txtGroupName") as TextBox;
        //    TextBlock tblock = stk.FindName("tblkGroupName") as TextBlock;
        //    tblock.Visibility = System.Windows.Visibility.Visible;
        //    tb.Visibility = Visibility.Collapsed;
        //    
        //}
        public static void SendFile(slPanel.Web.tblProjectGroup group, int projectid)
        {
            System.Windows.Controls.OpenFileDialog d = new OpenFileDialog();
            d.Filter = "Image (*.png, *.jpg) |*.png;*.jpg";
            //  d.ShowDialog();
            //try
            //{
            //    string filename = d.File.FullName;
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //    return;
            //}
            if (d.ShowDialog() == true)
            {

                Stream stream = d.File.OpenRead();

                Uri u = new Uri(Application.Current.Host.Source, "../Upload.ashx/?filename=" + d.File.Name + "&projectid=" + projectid);

                // MessageBox.Show(u.ToString());
                byte[] buffer = new byte[d.File.Length];
                stream.Read(buffer, 0, (int)d.File.Length);
                stream.Close();
                WebClient wc = new WebClient();
                wc.OpenWriteCompleted += (s, ee) =>
                {
                    if (ee.Error != null)
                    {
                        MessageBox.Show(ee.Error.Message);
                        return;
                    }
                    Stream outputStream = ee.Result;
                    outputStream.Write(buffer, 0, buffer.Length);
                    outputStream.Close();
                    MessageBox.Show("檔案上傳完成!");

                    group.GroupPicture = d.File.Name;
                    group.IsPictureDownload = true;

                    //System.Windows.Media.Imaging.BitmapImage img = new System.Windows.Media.Imaging.BitmapImage(new Uri(group.PicUrl));

                };
                wc.OpenWriteAsync(u);

            }
        }
开发者ID:ufjl0683,项目名称:LedControlPanel,代码行数:72,代码来源:Panel.xaml.cs

示例12: OpenWriteAsync_CloseStream

		public void OpenWriteAsync_CloseStream ()
		{
			WebClient wc = new WebClient ();
			bool complete_open = false;
			bool complete_close = false;
			int tid = Thread.CurrentThread.ManagedThreadId;
			wc.OpenWriteCompleted += delegate (object sender, OpenWriteCompletedEventArgs e) {
				CheckStream (e.Result, false, "Result.Before");
				e.Result.Close ();
				CheckStream (e.Result, true, "Result.After");
				complete_open = true;
			};
			wc.WriteStreamClosed += delegate (object sender, WriteStreamClosedEventArgs e) {
				Assert.AreSame (wc, sender, "Sender");
				Assert.AreEqual (Thread.CurrentThread.ManagedThreadId, tid, "ManagedThreadId");
				CheckDefaults (wc);
				Assert.IsTrue (e.Error is SecurityException, "Error");
				complete_close = true;
			};
			Enqueue (() => { wc.OpenWriteAsync (new Uri ("http://www.mono-project.com"), null); });
			EnqueueConditional (() => complete_open && complete_close);
			EnqueueTestComplete ();
		}
开发者ID:shana,项目名称:moon,代码行数:23,代码来源:WebClientTest.cs

示例13: OpenWriteAsync_UserToken

		public void OpenWriteAsync_UserToken ()
		{
			WebClient wc = new WebClient ();
			bool complete = false;
			int tid = Thread.CurrentThread.ManagedThreadId;
			wc.OpenWriteCompleted += delegate (object sender, OpenWriteCompletedEventArgs e) {
				Assert.AreEqual (Thread.CurrentThread.ManagedThreadId, tid, "ManagedThreadId");
				CheckDefaults (wc);
				Assert.IsFalse (e.Cancelled, "Cancelled");
				Assert.IsNull (e.Error, "Error");
				Assert.AreEqual (String.Empty, e.UserState, "UserState");

				CheckStream (e.Result, false, "Result.Before");
				e.Result.Close ();
				CheckStream (e.Result, true, "Result.After");
				complete = true;
			};
			Enqueue (() => { wc.OpenWriteAsync (new Uri ("http://www.mono-project.com"), null, String.Empty); });
			EnqueueConditional (() => complete);
			EnqueueTestComplete ();
		}
开发者ID:shana,项目名称:moon,代码行数:21,代码来源:WebClientTest.cs

示例14: guardarImagen

        private void guardarImagen()
        {
            WebClient client = new WebClient();
            client.WriteStreamClosed += (s, a) =>
            {
                if (a.Error == null)
                {
                    //El archivo fue subido correctamente
                }
            };

            client.OpenWriteCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    //El Stream ha sido abierto correctamente
                    //Escribe la secuencia de bytes en el Stream abierto

                    Stream stream = a.Result;
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Flush();
                    stream.Close();
                }
            };

            //Abre un Stream de escritura
            client.OpenWriteAsync(new Uri(string.Format("/Upload.aspx?n={0}", fileName),
                UriKind.RelativeOrAbsolute));
        }
开发者ID:Ginangely,项目名称:Proyecto1,代码行数:29,代码来源:CuRegistrarProducto.xaml.cs

示例15: OpenWriteAsync_MainThread

		public void OpenWriteAsync_MainThread ()
		{
			DependencyObject TestPanel = this.TestPanel;
			Thread main_thread = Thread.CurrentThread;
			AssertFailedException afe = null;
			bool done = false;

			/* Check that the OpenWriteAsync events are executed on the main thread when the request was done on the main thread */

			WebClient wc = new WebClient ();
			if (!RunningFromHttp) {
				EnqueueTestComplete ();
				return;
			}

			wc.UploadProgressChanged += new UploadProgressChangedEventHandler (delegate (object sender, UploadProgressChangedEventArgs dpcea) {
				try {
					Assert.IsTrue (TestPanel.CheckAccess ());
					Assert.AreEqual (main_thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId, "Equal thread ids in UploadProgressChanged");
				}
				catch (AssertFailedException e) {
					afe = e;
				}
			});
			wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler (delegate (object sender, OpenWriteCompletedEventArgs orcea) {
				try {
					Assert.IsTrue (TestPanel.CheckAccess ());
					Assert.AreEqual (main_thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId, "Equal thread ids in OpenWriteCompleted");
				}
				catch (AssertFailedException e) {
					afe = e;
				}
				finally {
					done = true;
				}
			});
			wc.WriteStreamClosed += new WriteStreamClosedEventHandler (delegate (object sender, WriteStreamClosedEventArgs wscea) {
				try {
					Assert.IsTrue (TestPanel.CheckAccess ());
					Assert.AreEqual (main_thread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId, "Equal thread ids in WriteStreamClosed");
				}
				catch (AssertFailedException e) {
					afe = e;
				}
			});
			wc.OpenWriteAsync (IndexHtml);
			EnqueueConditional (() => done);
			Enqueue (() => {
				if (afe != null)
					throw afe;
			});
			EnqueueTestComplete ();
		}
开发者ID:kangaroo,项目名称:moon,代码行数:53,代码来源:WebClientTest.cs


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