【问题标题】:Upload a file referenced via URL上传通过 URL 引用的文件
【发布时间】:2010-11-22 23:49:16
【问题描述】:

我有指向图像的网址,例如: http://cg009.k12.sd.us/images/smilefacemoving.gif

而不是用户将插入文件,我想将此文件(图像)绑定到 c# 文件上传控件。

所以文件上传对象将保存这个文件(图像)。

【问题讨论】:

    标签: c# .net upload


    【解决方案1】:

    只需在您的页面上有一个文本框,让他们输入一个 URL,然后在提交表单时执行此操作...

    string url = YOUR_TEXTBOX.Text();
    Uri uri;
    
    try {
     uri = new Uri(url);
    }
    catch (UriFormatException ex) {
     // Error
     throw ex;
    }
    
    byte[] file;
    
    using (System.Net.WebClient client = new System.Net.WebClient()) {
     file = client.DownloadData(uri);
    }
    
    // now you have the file
    

    注意上传的病毒:)

    【讨论】:

      【解决方案2】:

      老实说,我不确定你在问什么。您是否在问如何使用 fileupload 控件将通过 URL 引用的文件上传到您自己的服务器?

      【讨论】: