<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function xx() {
            document.getElementById("FileUpload1").click();
            document.getElementById("fpurl").value = document.getElementById("FileUpload1").value;
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div><table class="tableBorder">
    <tr>
        <td class="Margins"><input type="text" id="fpurl" class="inputItemText" /></td>
        <td class="Margins"><img alt="" src="../Resource/Images/search.gif" onclick="xx();"/></td>
    </tr>
</table>
    <asp:FileUpload ID="FileUpload1" runat="server" style="display:none"/>    <asp:Button ID="Button1" runat="server" Text="提交" />
    </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    http://blog.csdn.net/cpp2017/article/details/4418202
      

  2.   


    /// <param name="myFileUpload">上传控件ID</param>
        /// <param name="allowExtensions">允许上传的扩展文件名类型,如:string[] allowExtensions = { ".doc", ".xls", ".ppt", ".jpg", ".gif" };</param>
        /// <param name="maxLength">允许上传的最大大小,以M为单位</param>
        /// <param name="savePath">保存文件的目录,注意是绝对路径,如:Server.MapPath("~/upload/");< /param>
        /// <param name="saveName">保存的文件名,如果是'""'则时间为文件名保存</param>
        public static void Upload(FileUpload myFileUpload, string[] allowExtensions, int maxLength, string savePath, string saveName)
        {
            // 文件格式是否允许上传
            bool fileAllow = false;
            //检查是否有文件案
            if (myFileUpload.HasFile)
            {
                // 检查文件大小, ContentLength获取的是字节,转成M的时候要除以2次1024
                if (myFileUpload.PostedFile.ContentLength / 1024 / 1024 >= maxLength)
                {
                    throw new Exception("上传文件超过允许上传容量!");
                }            //取得上传文件之扩展文件名,并转换成小写字母
                string fileExtension = System.IO.Path.GetExtension(myFileUpload.FileName).ToLower();
                string tmp = "";   // 存储允许上传的文件后缀名
                //检查扩展文件名是否符合限定类型
                for (int i = 0; i < allowExtensions.Length; i++)
                {
                    tmp += i == allowExtensions.Length - 1 ? allowExtensions[i] : allowExtensions[i] + ",";
                    if (fileExtension == allowExtensions[i])
                    {
                        fileAllow = true;
                    }
                }            if (fileAllow)
                {
                    string myTime = DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString("000");
                    DirectoryInfo myFolder = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath(savePath));                if (!myFolder.Exists)
                    { myFolder.Create(); }                try
                    {
                        string path = System.Web.HttpContext.Current.Server.MapPath(savePath + "/" + (saveName == "" ? myTime : saveName));
                        //存储文件到文件夹
                        myFileUpload.SaveAs(path);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                else
                {
                    throw new Exception("文件格式不符,可以上传的文件格式为:" + tmp);
                }
            }
            else
            {
                throw new Exception("请选择要上传的文件!");
            }
        }    //以下是测试的代码:
        //try
        //  {
        //     string[] ss = { ".jpg", ".gif" };
        //     Jproc.Jupload.Upload(FileUpload1, ss, 1, "aaaaaaa", "");
        //     Label1.Text = "文件上传成功!";
        //  }
        //  catch (Exception ex)
        //  {
        //     Label1.Text =ex.Message;
        //  }
      

  3.   

     function xx() {
      document.getElementById("FileUpload1").click();
      document.getElementById("fpurl").value = document.getElementById("FileUpload1").value;
     document.getElementById("form1").submit(); }你的这种方法只对某些IE可用。,非IE不支持这种方法。你还是放弃吧