1

I have been working on a Windows Phone Application that takes images and text together and upload them to a server.

There is a problem while debugging the application. The problem seems technical. I really don't have a clue on what to do.

That's why I wanted to post this issues here. I would really appreciate the help offered to me here if someone of you could assist in solving this problem.

I really appreciate the work being done here. Without you guys, we really wouldn't have made it this far. You give us the opportunity to learn from our mistakes.

Thanks again.

Please check if my code needs any adjustments.

Here is the error message that pops up whenever I debug on the Emulator:

Failed to assign to property 'System.Windows.Controls.Primitives.ButtonBase.Click'. [Line: 41 Position: 250]

This is my first post so I can't post images, unfortunately.

I appreciate the work being done here.

   private void button3_Click(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)

       //void photoChooserTask_Completed(object sender, PhotoResult e)
        //{

            {
                System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
                bmp.SetSource(e.ChosenPhoto);
                image1.Source = bmp;
                byte[] sbytedata = ReadToEnd(e.ChosenPhoto);
                string s = sbytedata.ToString();
                WebClient wc = new WebClient();
                Uri u = new Uri("ftp://ftp.icupload.cs201.com/icupload.cs201.com/images/");
                wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
                wc.OpenWriteAsync(u, "POST", sbytedata);

            }
        }
        public static void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                object[] objArr = e.UserState as object[];
                byte[] fileContent = e.UserState as byte[];

                Stream outputStream = e.Result;
                outputStream.Write(fileContent, 0, fileContent.Length);
                outputStream.Flush();
                outputStream.Close();
                string s = e.Result.ToString(); ;

            }
        }
        public static byte[] ReadToEnd(System.IO.Stream stream)
        {
            long originalPosition = stream.Position;
            stream.Position = 0;

            try
            {
                byte[] readBuffer = new byte[4096];

                int totalBytesRead = 0;
                int bytesRead;

                while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
                {
                    totalBytesRead += bytesRead;

                    if (totalBytesRead == readBuffer.Length)
                    {
                        int nextByte = stream.ReadByte();
                        if (nextByte != -1)
                        {
                            byte[] temp = new byte[readBuffer.Length * 2];
                            Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
                            Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
                            readBuffer = temp;
                            totalBytesRead++;
                        }
                    }
                }

                byte[] buffer = readBuffer;
                if (readBuffer.Length != totalBytesRead)
                {
                    buffer = new byte[totalBytesRead];
                    Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
                }
                return buffer;
            }
            finally
            {
                stream.Position = originalPosition;
            }    

    }

Here is line 41 ... Position 252 is the "Click = myButton3_Click"

<Button BorderBrush="#FFFF7300" Content="Capture Photo" FontSize="22" Foreground="#FFFF7300" Height="78" Margin="263,23,-10,0" Name="myButton" VerticalAlignment="Top" Click="button2_Click" FontFamily="Tahoma" BorderThickness="4" />
        <Image Height="275" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="269" />
        <Button Content="Comment &amp; Location" Height="72" HorizontalAlignment="Left" Margin="92,599,0,0" Name="button1" VerticalAlignment="Top" Width="294" Foreground="#FFFF7300" OpacityMask="#FFFF7300" BorderBrush="#FF091A08" FontFamily="Tahoma" FontWeight="Normal" Background="Transparent" Click="button1_Click" />
        <Button Content="Select Photo" HorizontalAlignment="Left" Margin="264,107,0,0" Name="button2" Width="202" FontSize="24" Foreground="#FFFF7300" FontFamily="Tahoma" Background="Transparent" BorderBrush="#FFFF7300" BorderThickness="4" Height="78" VerticalAlignment="Top" Click="button2_Click_1" />
        <Button Content="Upload" Height="84" HorizontalAlignment="Left" Margin="272,191,0,0" Name="myButton3" VerticalAlignment="Top" Width="186" BorderBrush="#FFFF7300" BorderThickness="4" FontFamily="Tahoma" FontSize="26" Foreground="#FFFF7300" Click="myButton3_Click" ClickMode="Release" DataContext="{Binding}" />
        <TextBlock Height="200" HorizontalAlignment="Left" Margin="28,290,0,0" Name="textBlock1" Text="" VerticalAlignment="Top" Width="400" FontSize="30" TextTrimming="WordEllipsis" TextWrapping="Wrap" />

After all the changes you mentioned here, I still get three same errors.

Error 2 'System.Windows.RoutedEventArgs' does not contain a definition for 'ChosenPhoto' and no extension method 'ChosenPhoto' accepting a first argument of type 'System.Windows.RoutedEventArgs' could be found (are you missing a using directive or an assembly reference?) C:\Users\Yaseen\Desktop\IC Final\Phone Application\MainPage.xaml.cs 107 41 Phone Application

These come directly after the button3 syntax

Taha Faris
  • 11
  • 3
  • The problem is not in the code you posted, but in your XAML, therefore the XAMLParse error youre getting. Could you post line 41 of the corresponding XAML (and a few lines before and after that). – Philip Daubmeier May 11 '12 at 10:41

2 Answers2

2

I don't think the code you have posted is related to the error message.

But your problems seems to be the same as

here

and here

Community
  • 1
  • 1
Manuel Amstutz
  • 1,311
  • 13
  • 33
1

You have the click in your XAML set to myButton3_Click, when the codebehind has only button3_Click.

These are supposed to match.

Robaticus
  • 22,857
  • 5
  • 54
  • 63