通过ASP.NET损坏的文件的远程文件下载 [英] Remote file Download via ASP.NET corrupted file

查看:111
本文介绍了通过ASP.NET损坏的文件的远程文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是code下面我已经在论坛上的一个发现,下载远程服务器上的文件。现在看来,这是工作。然而,下载的文件被破坏,我不能解压缩。

你有任何想法,为什么会这样?或者,如果我的做法是错误的,你能不能给我建议一个更好的办法吗?

 保护无效的Page_Load(对象发件人,EventArgs的发送)
    {        字符串的URL = \"http://server/scripts/isynch.dll?panel=AttachmentDownload&NoteSystem=SyncNotes&NoteType=Ticket&NoteId=1&Field=supp&File=DisplayList%2etxt\";
        HttpWebRequest的REQ =(HttpWebRequest的)WebRequest.Create(URL);
        req.Credentials =新的NetworkCredential(用户,传);
        HttpWebResponse RESP =(HttpWebResponse)req.GetResponse();
        ////初始化输出流
        Response.Clear();
        Response.ContentType =应用程序/八位字节流;
        Response.AppendHeader(内容处置,附件;文件名=+DisplayList.txt);
        Response.AppendHeader(内容长度,resp.ContentLength.ToString());        ////填充输出流
        字节[] = ByteBuffer中新的字节[resp.ContentLength]
        流RS = req.GetResponse()GetResponseStream()。        rs.Read(ByteBuffer的,0,ByteBuffer.Length);
        Response.BinaryWrite(ByteBuffer的);
        Response.Flush();        ///清理
        到Response.End();
        rs.Dispose();
    }


解决方案

上的 http://support.microsoft.com/default.aspx?scid=kb;en-us;812406 解决我的问题。非常感谢@Aliostad为他的努力来帮助我。

I am using the code below which I have found on one of the forums to download a file in remote server. it seems it is working. However, the downloaded file is corrupted and I cannot unzip.

Do you have any idea why it is so? or if my approach is wrong, could you suggest me a better way please?

     protected void Page_Load(object sender, EventArgs e)
    {

        string url = "http://server/scripts/isynch.dll?panel=AttachmentDownload&NoteSystem=SyncNotes&NoteType=Ticket&NoteId=1&Field=supp&File=DisplayList%2etxt";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Credentials = new NetworkCredential("user", "pass");
        HttpWebResponse resp = (HttpWebResponse)req.GetResponse();


        ////Initialize the output stream
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition:", "attachment; filename=" + "DisplayList.txt");
        Response.AppendHeader("Content-Length", resp.ContentLength.ToString());

        ////Populate the output stream
        byte[] ByteBuffer = new byte[resp.ContentLength];
        Stream rs = req.GetResponse().GetResponseStream();

        rs.Read(ByteBuffer, 0, ByteBuffer.Length);
        Response.BinaryWrite(ByteBuffer);
        Response.Flush();

        ///Cleanup
        Response.End();
        rs.Dispose();
    }

解决方案

the article on http://support.microsoft.com/default.aspx?scid=kb;en-us;812406 solved my problem. Many thanks to @Aliostad for his effort to help me.

这篇关于通过ASP.NET损坏的文件的远程文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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