在客户端计算机上而不是在服务器计算机上下载文件 [英] Download a file on client machine rather than on server machine

查看:89
本文介绍了在客户端计算机上而不是在服务器计算机上下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件在服务器上,我希望它在运行远程URL的客户端计算机上下载。任何解决方案



我尝试过:



A file is on server i want it to download on client machine where the remote URL is running. Any Solutions

What I have tried:

<pre> protected void Lnk_Download_Click(object sender, EventArgs e)
    {
        try
        {
            string RemoteURL = "D:/Balaji/PCRT.DAT";
            string Fname = "PCRTnew.DAT";
            WebClient WB = new WebClient();
            WB.DownloadFile(RemoteURL, @"D:/"+Fname);
            WebMsgBox.Show("File Downloaded to Location- D:/" + Fname,this.Page); 

        }
        catch (Exception Ex)
        {
            ExceptionLogging.SendErrorToText(Ex);
        }
    }

推荐答案

简答:

C#是服务器端代码,如果客户端没有请求,服务器无法向客户端发送文件。

只有解决方案是让客户端请求文件。

当前页面自动请求作为页面(图片)一部分的文件,用户明确指定转到客户端文件系统的文件。
Short answer:
C# is server side code, the server can not send a file to client if the client didn't requested it.
Only solution is having the client requesting the file.
Current page is automatically requesting file that are part of the page (pictures), files that go to client file system are explicitly by user.


您是否希望Web服务器在本地计算机上保存文件?不,你不会这样,其他人也不希望你的网站保存他们的文件。出于安全原因,您不能尝试做什么。
Would you want web servers saving files on your local machine? No, you wouldn't so other people don't want your site saving files on theirs either. What you're trying to do isn't possible for security reasons.


这篇关于在客户端计算机上而不是在服务器计算机上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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