我在页面动态生成了一个 上传控件
现在我想上传图片或flash
但是现在获得不到页面上的控件(动态生成的控件在页面上不显示)
所以无法上传
现在不知道该怎么做
请各位多多指教
现在我想上传图片或flash
但是现在获得不到页面上的控件(动态生成的控件在页面上不显示)
所以无法上传
现在不知道该怎么做
请各位多多指教
解决方案 »
- 如何实现内网对特定电脑开放
- .net 网站的问题。帮帮忙~~
- asp.net中用什么控件可以可以像TreeView那样显示分层数据?
- 紧急求救!点分页,点多几次出现"stack overflow at line:0"
- 做一个很简单的系统,问下差不多这样的系统有人做过吗
- 问一个比较弱智的问题:为什么打开项目总是报"无法从服务器获取项目文件..."
- 页面文字大小的问题,急,请教
- 我从别人机器上拷贝过来的一个WEB工程,我不知道原来是放在哪个目录下编译的,在我机器上打开工程文件说路径不对,怎么解决?
- 哪位老大用过google checkout的付款方式??谁有源码!谢谢
- 急!急!急!在线等候,高分送上!关于下拉菜单的问题
- 新手求教网站开发过程以及发布中需要注意的安全性问题!跪求!!!
- 如何将数据库数据动态绑定到Table
{
Button btn = new Button();
btn.ID = "btn_bank_submit";
btn.Text = "网上支付";
btn.Click += new EventHandler(btn_bank_submit_Click);
this.Controls.Add(btn);
}类似这样 。
<head runat="server">
<title></title>
<style type="text/css">
<!--
ul, li {
list-style-type: none;
padding: 0px;
margin: 0px;
}
a {
color: #000;
text-decoration: none;
font-size: 12px;
font-weight: bold;
line-height: 30px;
margin-left: 10px;
}
-->
</style>
<script type="text/javascript" src="../js/jquery-1.4.js"></script>
<script type="text/javascript">
var i=1;
function add(){
document.getElementById("list").innerHTML+="<li class=\"li\"><input type=\"file\" name=\"imgFile"+i+"\" /><a href=\"javascript:add();\">+</a><a href=\"javascript:del();\">-</a></li>";
i+=1;
}
function del(){
$(".li:first").detach();
}
</script>
</head>
<body>
<div id="upload">
<form action="../ashx/upload.ashx" method="post" enctype="multipart/form-data">
<ul id="list">
<li><input type="file" name="imgfile" /><a href="javascript:add();">+</a></li>
</ul>
<div>
<input type="submit" value="上传" onclick="javascript:document.getElementById('upload').style.display='none'; document.getElementById('loading').style.display='block';" />
</div>
</form>
</div>
<div id="loading" style="display:none;">文件上传中……</div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Globalization;
using System.Collections;namespace Web.asp_bin.admin.ashx
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
public class upload : IHttpHandler
{
//文件保存目录路径
private String savePath = "/upload/images/" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM") + "/";
//文件保存目录URL
private String saveUrl = "/upload/images/" + DateTime.Now.ToString("yyyy") + DateTime.Now.ToString("MM") + "/"; //定义允许上传的文件扩展名
private String fileTypes = new Alvin.BLL.Setting().AttachmentType; //从网站设置中读取可以上传的类型//System.Configuration.ConfigurationManager.AppSettings["fileTypes"];
//最大文件大小
private int maxSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings["maxSize"]) * 1024;
private HttpContext context;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
this.context = context;
string strID=context.Request.QueryString["ID"];//返回的控件ID
string path = context.Request.QueryString["Path"];
if (!string.IsNullOrEmpty(path))
{
if(System.IO.Directory.Exists(context.Server.MapPath(path)))
{
savePath=path;
saveUrl=path;
}
}
//HttpPostedFile imgFile = context.Request.Files[0];
string retPath = string.Empty;
for (int i=0; i<context.Request.Files.Count;i++)
{
HttpPostedFile imgFile = context.Request.Files[i];
if (imgFile == null)
{
context.Response.Write("请选择文件。");
return;
} String dirPath = context.Server.MapPath(savePath);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);//如果不存在该文件夹,则创建文件夹
} String fileName = imgFile.FileName;
String fileExt = Path.GetExtension(fileName).ToLower();
ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(',')); if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize)
{
context.Response.Write("<span style=\"margin: 0px;padding: 0px;font-size: 12px;\">上传文件大小超过限制。<a href=../inc/upload.aspx?ID=" + strID + ">点击重新选择上传</a></span>");
return;
} if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
{
context.Response.Write("<span style=\"margin: 0px;padding: 0px;font-size: 12px;\">上传文件扩展名是不允许的扩展名。<a href=../inc/upload.aspx?ID=" + strID + ">点击重新选择上传</a></span>");
return;
} String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + i + fileExt;
String filePath = dirPath + newFileName;
imgFile.SaveAs(filePath);
String fileUrl = saveUrl + newFileName;
retPath += fileUrl + ",";
}
retPath = retPath.Substring(0, retPath.Length - 1);
if (string.IsNullOrEmpty(strID))
{
context.Response.Write("<span style=\"margin: 0px;padding: 0px;font-size: 12px;\">上传成功!<a href=" + context.Request.UrlReferrer.ToString() + ">我还要上传</a></sapn>");
}
else
{
context.Response.Write("<script type=\"text/javascript\"> parent.document.getElementById(\"" + strID + "\").value=\"" + retPath + "\";</script><span style=\"margin: 0px;padding: 0px;font-size: 12px;\">上传成功!<a href=" + context.Request.UrlReferrer.ToString() + ">点击重新上传</a></sapn>");
}
} public bool IsReusable
{
get
{
return false;
}
}
}
}