下载正常,但无法在所需页面中打开! [英] Downloading working fine but not getting opened in the required page !

查看:64
本文介绍了下载正常,但无法在所需页面中打开!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我提供了一种功能,用户可以选择要下载的内容,并通过文件保存打开对话框轻松地将其保存在新选项卡中.不错,可以接受,但此处存在跨浏览器问题.因为在Mozilla中,只要文件未完全下载,新选项卡就会保留,而在chrome中,即使下载完成,页面仍会保留.有时需要花费一些时间来下载文件(.csv),所以我创建了一个带有HTML标记的页面,请不要关闭此窗口,但是它永远无法正确完成.我收到一个错误消息:请求eroor 404,找不到类似的文件,因此它阻止了事情的正确进行.你能给我一些建议吗?
这是我的代码:

Hi,
I have made a functionality where user selects something to download and get it in a new tab easily with the file save open dialogue box. It is nice and acceptable but the cross browser issue prevails here. Because in Mozilla the new tab stays as long as the file is not fully downloaded but in chrome the page persists even if the download is complete. Sometime it takes time to download the file(.csv) so I created a page that has HTML mark up as please do not close this window but however it never gets properly done. I am getting a error : request eroor 404, file was not found something like that and thus it is preventing the things to happen correctly. Could you please suggest me something out of it ???
Here is my code :

 Session["download_file_link"] = strResult;
                string strDownloadPageURL = strResult;
                ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( 'Download.aspx', null, 'height=400,width=800,status=yes,toolbar=no,menubar=no,location=no' );", true);

/* than on download page */

public void Download_file_for_user(string strFilename)
    {
        System.Net.HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.cybexexim.net/Downloads/" + strFilename);
        HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();<-- error here
        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();
        Response.AppendHeader("Content-Disposition:", "attachment; filename=" + strFilename + "");
        Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString());
        Response.ContentType = "application/download";
        Response.Close();
        Session.Remove("download_file_link");
        Response.End();
    }



在页面加载时调用此方法.它仍然不允许您正确打开此页面,也无法下载文件.但是,如果我在上面使用的javascript上使用我的下载字符串directky,则不存在问题,而是download.aspx页面
永远不会来.请帮忙!



calling this method on page load. It still doesnt allows to open this page properly and file doesnt gets download. However If I use my download string directky on javascript used above than no prob exists but download.aspx page
never comes. Please help !

推荐答案

尝试类似的方法.

Try something like this.

 System.Net.HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.cybexexim.net/Downloads/" + strFilename);
request.ContentType = "application/json; charset=utf-8";
request.Credentials = CredentialCache.DefaultCredentials;
try
{
    response = (HttpWebResponse)request.GetResponse();

    // perform normal processing
}
catch(WebException ex)
{
    // are you sure you just want to swallow the exception like this?
    continue;
}





如果仍然抛出错误,请捕获错误并让我们知道错误消息.





if it still throws error, catch the error and let us know the error message.


这篇关于下载正常,但无法在所需页面中打开!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆