I create a webpage that will download our APK files to Android Smartphone but when I try to do it on Android, I get HTML instead of download window. But it worked perfectly on my PC. Heres my code.
public static void DownloadFile(string filename, string sContentType, System.Web.UI.Page page)
{
string path = page.Server.MapPath(filename); //get file object as FileInfo
System.IO.FileInfo file = new System.IO.FileInfo(path); //-- if the file exists on the server
if (file.Exists)
{
page.Response.Clear();
page.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
page.Response.AddHeader("Content-Length", file.Length.ToString());
if(sContentType.Length > 0)
page.Response.ContentType = sContentType;
else
page.Response.ContentType = "application/octet-stream";
page.Response.WriteFile(file.FullName);
page.Response.Flush();
page.Response.End(); //if file does not exist
cortejor
Member
14 Points
15 Posts
Download .APK from Android Phone
Aug 26, 2011 03:19 AM|LINK
I create a webpage that will download our APK files to Android Smartphone but when I try to do it on Android, I get HTML instead of download window. But it worked perfectly on my PC. Heres my code.
public static void DownloadFile(string filename, string sContentType, System.Web.UI.Page page)
{
string path = page.Server.MapPath(filename); //get file object as FileInfo
System.IO.FileInfo file = new System.IO.FileInfo(path); //-- if the file exists on the server
if (file.Exists)
{
page.Response.Clear();
page.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
page.Response.AddHeader("Content-Length", file.Length.ToString());
if(sContentType.Length > 0)
page.Response.ContentType = sContentType;
else
page.Response.ContentType = "application/octet-stream";
page.Response.WriteFile(file.FullName);
page.Response.Flush();
page.Response.End(); //if file does not exist
}
}
emulator