Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2012

    Question WP8 - WebBrowser class : How to handle downloading of file?

    I have created a simple app in WP8 to display web pages using the Microsoft.Phone.Controls.WebBrowser class. I am able to load the page, navigate links, move back and forward in history. Apart from this basic functionality I also want to provide means to download files which cannot be displayed within the browser like say .ppt or .mp3.

    I have not been able to find anything in the WebBrowser class documentation to initiate a download. There is just a Navigate function which takes a URL to load.

    So can a download be done using WebBrowser class?

    Or is there any way to automatically invoke the system viewer for the file (like powerpoint for ppt) which has been downloaded?

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012

    Re: WP8 - WebBrowser class : How to handle downloading of file?

    No WebBrowser can't download file but here are two classes that can do it :
    You can use WebClient or HttpWebRequest

    WebClient client = new WebClient();
    client.OpenReadCompleted += new OpenReadCompletedEventHandler(YourMethodToGetTheFile_OpenReadCompleted);
    client.OpenReadAsync(new Uri("http://www.WebSite.com/TheFile.ppt"));
    var uri = new Uri("http://www.WebSite.com/TheFile.ppt");
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
        request.BeginGetResponse(new AsyncCallback(YourMethodToGetTheFile_AsyncCallBack), request);
    You can use one of the snippets above and then simply store the stream you get as a response in the IsolatedStorageFile
    something like this for the WebClient
    void YourMethodToGetTheFile_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        var storeFile = IsolatedStorageFile.GetUserStoreForApplication();
        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("TheFile.ppt", System.IO.FileMode.Create, storeFile ))
            byte[] buffer = new byte[1024];
            while (e.Result.Read(buffer, 0, buffer.Length) > 0)
                stream.Write(buffer, 0, buffer.Length);
    Don't forget to delete the file if exist in the IsolatedStorage, I didn't handle it in the example.

Similar Threads

  1. How to handle Incomming Call using CTelephony class
    By jsscb in forum Symbian User Interface
    Replies: 4
    Last Post: 2011-04-07, 09:03
  2. Replies: 7
    Last Post: 2009-08-04, 08:21
  3. how to handle send() function in CBluetoothSynchronousLink class
    By hasiamar in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2008-04-24, 07:44
  4. How to Handle TFileText class..
    By Tatavarthi in forum Symbian
    Replies: 4
    Last Post: 2008-03-07, 17:13
  5. which class can handle input mode
    By yql in forum Symbian
    Replies: 15
    Last Post: 2007-08-20, 11:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts