如题。需要一定观赏性,不考虑input的file类型。
描述:希望点击一个按钮、文字、图片(总之不需要显示路径的文本框就行。)然后弹出一个窗口用于选择文件的路径。
补充:只要用于文件的导入和导出。
应该如何实现?
在线等...

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MUploadF.aspx.cs" Inherits="WebApp.uploadify.MUploadF" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
         <link href="/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            .Userupload
            {
                float: left;
                list-style: none;
            }
            .Userupload li
            {
                color: #666666;
                display: block;
                text-align: left;
                vertical-align: middle;
            }
            .AlbumButtBg
            {
                float: left !important;
            }
            .UpLoadType
            {
                height: 30px;
                line-height: 30px;
                float: right;
            }
        </style>    <script type="text/javascript" src="/jquery/jquery.js"></script>    <script type="text/javascript" src="/uploadify/swfobject.js"></script>    <script type="text/javascript" src="/uploadify/jquery.uploadify.v2.1.0.js" charset="gb2312"></script>    <script type="text/javascript">
            $("#divAdd").ready(function() {
                var fileLmt = parseInt('<%= System.Configuration.ConfigurationManager.AppSettings["FileSize"]%>');
                var hs = 1024 * 1024;
                if (fileLmt > hs)
                    fileLmt = parseInt(fileLmt / hs);
                else
                    fileLmt = 1;            $("#lblFileSize").html(fileLmt);            $("#uploadify").uploadify({
                    buttonText: '...',
                    uploader: '/uploadify/uploadify.swf',
                    script: '/uploadify/UploadHandler.ashx?action=upload',
                    cancelImg: '/uploadify/cancel.png',
                    queueID: 'fileQueue',
                    buttonImg: '/uploadify/browsef.jpg',
                    rollover: true,
                    auto: false,
                    height: 27,
                    width: 56,
                    multi: false,
                    simUploadLimit: 1,
                    sizeLimit: '<%= System.Configuration.ConfigurationManager.AppSettings["FileSize"]%>',
                    fileExt: '<%=FileExt %>',
                    fileDesc: '<%=FileExt %>',
                    scriptData: { ASPSESSID: "<%=Session.SessionID %>", AUTHID: "<%=ClientAUTHID%>" },
                    onSelect: checkFile,
                    onComplete: fileUpload,
                    onAllComplete: upComplete,
                    onError: function(event, ID, fileObj, errorObj) {
                        if (errorObj.status == 404)
                            alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
                        else if (errorObj.type === "HTTP")
                            alert('error ' + errorObj.type + ": " + errorObj.status);
                        else if (errorObj.type === "File Size") {
                            alert(fileObj.name + ' ' + "文件大小超限!");
                        }
                        else
                            alert('error ' + errorObj.type + ": " + errorObj.info);                    location.href = location.href;
                    }
                });
            });        function checkFile(e, queueId, fileObj) {
                //            alert("唯一标识:" + queueId + "\r\n" +
                //                  "文件名:" + fileObj.name + "\r\n" +
                //                  "文件大小:" + fileObj.size + "\r\n" +
                //                  "创建时间:" + fileObj.creationDate + "\r\n" +
                //                  "最后修改时间:" + fileObj.modificationDate + "\r\n" +
                //                  "文件类型:" + fileObj.type
                //            );
                $.post("/handler/CommonHandler.ashx", { action: "checktemplatename", templatename: fileObj.name }, function(data) {
                    if (data == "0") {
                        $("#btnSave")[0].disabled = false;
                    } else if (data == "1") {
                        Boxy.alert("已存在相同名字的模板,请重新选择其他名称的模板文件", cancelUpload, { title: "操作失败" }); ;
                    } else if (data == "-1") {
                        Boxy.alert("您还没有登录,请先登录", function() {
                            location.href = "/login.aspx?returnurl=?<%=Request.RawUrl %>";
                        }, { title: "请登录" });
                    } else if (data == "-2") {
                        Boxy.alert("参数错误!", null, { title: "参数非法" });
                    }
                });
            }        function upComplete(event, uploadObj) {
                $("#divOpHint").show();
                $("#divAdd").hide();
                var cnt = parseInt(uploadObj.filesUploaded);
                if (cnt > 0) {
                    Boxy.alert('上传成功!', gotoTemplatesPage, { title: "成功" });
                }
                //            else {
                //                Boxy.alert('系统忙,请稍候再试!', null, { title: "操作失败" });
                //            }
            }        function fileUpload(event, ID, fileObj, response, data) {
                if (response == "-1") {
                    Boxy.alert("您还没有登录,请先登录");
                    location.href = "/login.aspx?returnurl=?<%=Request.RawUrl %>";
                }
                else if (response == "0") {
                }
                else if (response.length == 40) {            }
            }        function uploadFile() {
                //$("#uploadify").uploadifySettings("scriptData", { aid: $("#").val() }, null);
                $('#uploadify').uploadifyUpload();
            }        function gotoTemplatesPage() {
                location.href = "/Admin/TemplateList.aspx";
            }        function cancelUpload() {
                $('#uploadify').uploadifyClearQueue();
            }
        </script></head>
    <body>
        <form id="form1" runat="server">
        <div id="divAdd" style="min-height: 500px;">
            <div id="divUploadBody">
                <ul class="Userupload" style="width: 300px;">
                    <li>
                        <div style="height: 20px;">
                            请选择文件,文件小于<label id="lblFileSize"></label>M
                            <label id="lblPhotoCnt">
                            </label>
                        </div>
                    </li>
                    <li style="padding-top: 10px; padding-left: 10px;">
                        <div id="fileQueue">
                        </div>
                        <input type="file" name="uploadify" id="uploadify" />
                    </li>
                    <li style="padding-top: 10px;" id="liImgShow"></li>
                </ul>
                <div style="clear: both;">
                </div>
                <div class="UpLoadType">
                    <input id="btnSave" value="保存" type="button" onclick="uploadFile();" disabled="disabled" />
                    <input id="btnCancel" value="取消" type="button" onclick="cancelUpload()" /></div>
            </div>
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Security;namespace WebApp.uploadify {
        public partial class MUploadF : System.Web.UI.Page {
            protected string FileExt = "*.xlsx;";        public string ClientAUTHID {
                get {
                    string strAuthid = "";
                    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) {
                        strAuthid = Request.Cookies[FormsAuthentication.FormsCookieName].Value;
                    }
                    return strAuthid;
                }
            }        protected void Page_Load(object sender, EventArgs e) {        }
        }
    }
      

  2.   

    http://www.uploadify.com/demo/
    下载链接