How to file download and open in Windows Phone 7? RRS feed

  • Question

  • User-1179126167 posted

    Hi all,

    I am developing winodws phone application. I need to download and open a file when click "Download File".

    i have done this in asp.net by using the follwoing code.. it's working fine in asp.net.

    BUT, I need the same functionality in WINDOWS PHONE 7.

    protected void btnDownloadFile_Click(object sender, EventArgs e)





     private void DownloadFile()


            string localfilename = @"E:\sample.txt";

            FileStream liveStream = new FileStream(localfilename, FileMode.Open, FileAccess.Read);


            byte[] buffer = new byte[(int)liveStream.Length];

            liveStream.Read(buffer, 0, (int)liveStream.Length);



            string originalFilename = "downloadedFile.txt";



            Response.ContentType = "application/octet-stream";

            Response.AddHeader("Content-Length", buffer.Length.ToString());

            Response.AddHeader("Content-Disposition", "attachment; filename=" + originalFilename);







    Friday, March 4, 2011 1:25 AM


All replies

  • User-525215917 posted

    Take a look at my blog posting Windows Phone 7 Series development: reading RSS feeds There is example about how to download content from WP7 without freezing phone UI.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 4, 2011 2:33 AM
  • User724386313 posted

    I think what the OP is asking about is downloading a file from Internet Explorer by writing it to the response. This does not work in WP7 or WP8 using the code he mentioned, but does work on all desktop browsers.

    Sunday, March 17, 2013 1:59 AM