Last post Mar 17, 2013 01:59 AM by MBogert
Member
567 Points
392 Posts
Mar 04, 2011 01:25 AM|Eswaran_MCA|LINK
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)
{
DownloadFile();
}
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);
liveStream.Close();
string originalFilename = "downloadedFile.txt";
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + originalFilename);
Response.BinaryWrite(buffer);
Response.End();
thanks
r.eswaran.
Contributor
4050 Points
1004 Posts
MVP
Mar 04, 2011 02:33 AM|DigiMortal|LINK
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.
None
0 Points
1 Post
Mar 17, 2013 01:59 AM|MBogert|LINK
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.
Member
567 Points
392 Posts
How to file download and open in Windows Phone 7?
Mar 04, 2011 01:25 AM|Eswaran_MCA|LINK
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)
{
DownloadFile();
}
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);
liveStream.Close();
string originalFilename = "downloadedFile.txt";
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + originalFilename);
Response.BinaryWrite(buffer);
Response.End();
}
thanks
r.eswaran.
r. eswaran
Contributor
4050 Points
1004 Posts
MVP
Re: How to file download and open in Windows Phone 7?
Mar 04, 2011 02:33 AM|DigiMortal|LINK
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.
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
None
0 Points
1 Post
Re: How to file download and open in Windows Phone 7?
Mar 17, 2013 01:59 AM|MBogert|LINK
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.