2015-01-29 用户控件+swfupload引用资源路径出错

今天是周五,最近一直在忙碌,所谓忙碌就是将原来别人写好的代码移到新的地方,同时将里面使用 DexExpress换成repeater内容,再将之前的样式去掉 换成现在系统的样式。比较坑的是原来的代码所有 样式都在标签 内写的,我需要一行行找到去掉。在这里没有什么可说的,之中又遇到一个用户控件引用资源出错的问题,原来代码是使用绝对路径,现在想换成相对路径,但是查看后引用的位置总是不对,原来引用页面直接将用户控件的直接嵌入没有进行引用路径的转换,于是改为:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="swfupload1.ascx.cs"   Inherits="GYLYEQ.AppSupport.infomanage.Controls.swfupload1" EnableTheming="True" %>
<link href="<%=ResolveUrl("UploadControl/swfupload/style.css") %>" rel="stylesheet" type="text/css" />
<script src="<%=ResolveUrl("UploadControl/swfupload/swfupload.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/swfupload.queue.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/fileprogress.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/filegroupprogress.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/handlers.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/swfupload.speed.js") %>" type="text/javascript"></script>
<script src="<%=ResolveUrl("UploadControl/swfupload/hashtable.js") %>" type="text/javascript"></script>

<script type="text/javascript">
    var swfu;
    var hash;
    window.onload = function () {
        // 初始化HashTable 用于存放文件名
        hash = new HashTable();
        var settings = {
            flash_url:  "<%=ResolveUrl("UploadControl/swfupload/swfupload.swf") %>"   ,
            upload_url: "<%=ResolveUrl("UploadControl/uploadnewspic.ashx?job=add") %>",
            file_size_limit: "200 MB",
            file_types: "*.flv",
            file_types_description: "All Files",
            file_upload_limit: 0,
            file_queue_limit: 0,
            custom_settings: {

                progressTarget: "divprogresscontainer",
                progressGroupTarget: "divprogressGroup",
                //progress object
                container_css: "progressobj",
                icoNormal_css: "IcoNormal",
                icoWaiting_css: "IcoWaiting",
                icoUpload_css: "IcoUpload",
                fname_css: "fle ftt",
                state_div_css: "statebarSmallDiv",
                state_bar_css: "statebar",
                percent_css: "ftt",
                href_delete_css: "ftt",

                //sum object
                /*
                页面中不应出现以"cnt_"开头声明的元素
                */
                s_cnt_progress: "cnt_progress",
                s_cnt_span_text: "fle",
                s_cnt_progress_statebar: "cnt_progress_statebar",
                s_cnt_progress_percent: "cnt_progress_percent",
                s_cnt_progress_uploaded: "cnt_progress_uploaded",
                s_cnt_progress_size: "cnt_progress_size"
            },
            debug: false,

            // Button settings
            //button_image_url: "images/TestImageNoText_65x29.png",
            button_width: "55",
            button_height: "23",
            button_placeholder_id: "spanButtonPlaceHolder",
            button_text: '<span class="theFont" onclick="setType(this)">上传文件</span>',
            button_text_style: ".theFont { font-size: 12;color:#0068B7; }",
            button_text_left_padding: 0,
            button_text_top_padding: 0,
            button_cursor: SWFUpload.CURSOR.HAND,

            // The event handler functions are defined in handlers.js
            file_queued_handler: fileQueued,
            file_queue_error_handler: fileQueueError,
            upload_start_handler: uploadStart,
            upload_progress_handler: uploadProgress,
            upload_error_handler: uploadError,
            upload_success_handler: uploadSuccess,
            upload_complete_handler: uploadComplete,
            file_dialog_complete_handler: fileDialogComplete,
            queue_complete_handler: queueComplete
        };
        swfu = new SWFUpload(settings);
    };

</script>
<div>
    <span id="spanButtonPlaceHolder"></span>
    <div id="divprogresscontainer">
    </div>
    <div id="divprogressGroup">
    </div>
</div>

路径对了

对应的文件上传处理代码

 public void ProcessRequest(HttpContext context)
        {           
            if (context.Request.QueryString["job"] != null)
            {
                //获得图片存储目录
                string dir =  "~/UploadFiles/FJ_Upload/"; 

                string strJob = context.Request.QueryString["job"].ToString().ToLower();
                try
                {
                    if (strJob.Equals("add"))
                    {
                        HttpPostedFile file;

                        // 文件名
                        string upFileName = string.Empty;
                        string fileId = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);


                        for (int i = 0; i < context.Request.Files.Count; ++i)
                        {
                            file = context.Request.Files[i];
                            if (file == null || file.ContentLength == 0 || string.IsNullOrEmpty(file.FileName)) continue;

                            string fileExtension = new FileInfo(file.FileName).Extension.ToLower();

                            /// 将上传文件以不重复文件名形式保存到本站目录下
                            upFileName += dir + System.IO.Path.GetFileNameWithoutExtension(file.FileName) + "_" + fileId + fileExtension;

                            //file.SaveAs(upFileName);
                            file.SaveAs(HttpContext.Current.Server.MapPath(upFileName));

                        }
                        context.Response.StatusCode = 200;
                        context.Response.Write(upFileName);
                    }
                    if (strJob.Equals("del"))
                    {
                        string fileName = dir+context.Request.QueryString["id"].ToString(); 
                        File.Delete(fileName);
                        context.Response.StatusCode = 200;
                    }
                }
                catch (Exception ex)
                {
                    context.Response.StatusCode = 500;
                    context.Response.Write(ex.Message);
                    context.Response.End();
                }
                finally
                {
                    context.Response.End();
                }
            }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值