⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 download.aspx.cs

📁 ASP.NET多线程编程(二),ASP.NET多线程编程(二) .
💻 CS
字号:
using System;
using System.Globalization;
using System.Xml;
using System.Web;
using FredCK.FCKeditorV2;
using System.Text.RegularExpressions;

public partial class FCKeditor_download : FileWorkerBase
{
    protected override void OnLoad(EventArgs e)
    {
        string downloadUrl = Request.QueryString["txtUrl"];

        //判断格式
        Regex regObj = new Regex("http://(.*).(gif|jpg|jpeg|bmp|swf)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
        if (!regObj.IsMatch(downloadUrl))
        {
            SendResults(202);
            return;
        }

        int errorNumber = 0;
        string fileName = Guid.NewGuid().ToString() + downloadUrl.Substring(downloadUrl.LastIndexOf("."));
        string fileUrl = this.UserFilesPath + "image/" + fileName;

        //远程存储
        try
        {
            System.Net.WebClient wc = new System.Net.WebClient();
            wc.DownloadFile(downloadUrl, Server.MapPath(fileUrl));
        }
        catch (Exception ex)
        {
            SendResults(101, "", "", ex.Message);
        }

        //向客户端发送结果
        SendResults(errorNumber, fileUrl, fileName);

    }
    #region SendResults Method

    private void SendResults(int errorNumber)
    {
        SendResults(errorNumber, "", "", "");
    }

    private void SendResults(int errorNumber, string fileUrl, string fileName)
    {
        SendResults(errorNumber, fileUrl, fileName, "");
    }

    private void SendResults(int errorNumber, string fileUrl, string fileName, string customMsg)
    {
        Response.Clear();

        Response.Write("<script type=\"text/javascript\">");
        Response.Write("window.parent.OnUploadCompleted(" + errorNumber + ",'" + fileUrl.Replace("'", "\\'") + "','" + fileName.Replace("'", "\\'") + "','" + customMsg.Replace("'", "\\'") + "') ;");
        Response.Write("</script>");

        Response.End();
    }

    #endregion
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -