0

I found many tutorials using WebClient to upload files. by using webCleint.uploadFile.

But in WP8 there is no support. Anyone have any idea???

eeadev
  • 3,662
  • 8
  • 47
  • 100

1 Answers1

2

Check this article:http://chriskoenig.net/2011/08/19/upload-files-from-windows-phone/

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

            const int BLOCK_SIZE = 4096;

            Uri uri = new Uri("http://localhost:4223/File/Upload", UriKind.Absolute);

            WebClient wc = new WebClient();
            wc.AllowReadStreamBuffering = true;
            wc.AllowWriteStreamBuffering = true;

            // what to do when write stream is open
            wc.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[BLOCK_SIZE];
                        do
                        {
                            bytes = br.ReadBytes(BLOCK_SIZE);
                            bCount += bytes.Length;
                            bw.Write(bytes);
                        } while (bCount < fileSize);
                    }
                }
            };

            // what to do when writing is complete
            wc.WriteStreamClosed += (s, args) =>
            {
                MessageBox.Show("Send Complete");
            };

            // Write to the WebClient
            wc.OpenWriteAsync(uri, "POST");
        }

And this two: Upload image using ASP.NET WebAPI using a model http://blog.anthonybaker.me/2013/06/how-to-upload-file-from-windows-phone.html

Community
  • 1
  • 1
d.lavysh
  • 1,404
  • 14
  • 23
  • I Follow all that step, but i fact a problem, which is this, how i get my remote server ipaddress and the port??? var fileUploadUrl = @"http://:/fileupload"; – user3064311 Dec 19 '13 at 19:34
  • Where can i other my this ""http://localhost:4223/File/Upload"" i got bought a domain which is called www.comevox.com how can i know the port number? that path /File/upload is folder in the server? – user3064311 Dec 20 '13 at 20:52