Q:

Accessing the header in OpenReadCompleted Method on windows phone 8

I have an app that downloads an image to the phone and depending on the image category it will assign it to a news feed. I am using this function:
    private static void DownloadImage(string furl, string ids)
    {
        // Connect Again to the API
        WebClient client = new WebClient();
        client.Headers["NewsID"] = ids;

        string url = "www.xxx.com/image/xyz";

        client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
        client.OpenReadAsync(new Uri(url));
    }

    private static void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (e.Error == null && !e.Cancelled)
            {
                Stream reply = null;
                StreamReader s = null;

                // i am not able to read the sender who is a webclient to retrieve the information it is always skipping it 
                WebClient wcd = sender as WebClient;

                reply = (Stream)e.Result;
                s = new StreamReader(reply);
                //Console.WriteLine(s.ReadToEnd());
                s.Close();
                reply.Close();

                if (!myIsolatedStorage.DirectoryExists("ImageCache"))
                {
                    myIsolatedStorage.CreateDirectory("ImageCache");
                }

                //try
                //{//((MS.Internal.InternalMemoryStream)(e.Result)).FinalUri.Segments[2]
                var graphImage = e.Result;
                Random rand = new Random();
                string fileName = string.Format("ImageCache/{0}.jpg", rand.Next());
                IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);

                BitmapImage image = new BitmapImage();
                image.SetSource(e.Result);
                WriteableBitmap wb = new WriteableBitmap(image);

                // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                fileStream.Close();

                //}
                //catch (IsolatedStorageException ex)
                //{
                //IsolatedStorageException
                //Exception handle appropriately for your app  
                //}
            }
        }
    }

In the OpenReadComplete function which I'm using to download the image, I want to get the newsID from the header, and then assign it to the image before saving it into the database. I can't seem to access the header. Is this possible?

A:

I think you can read it with sender.
WebClient c = (WebClient)sender;
        string id = c.Headers["NewsID"];

