同时上载多个文件
2008-07-21 14:42
113 查看
Javascript代码:
<script language="javascript" type="text/javascript">
function addFile()
{
var filebutton = '<br><input type="file" size="50" name="file" class="Button" />';
document.getElementById('FileList').insertAdjacentHTML("beforeEnd",filebutton);
}
</script>
页面中:
<tr>
<td width="150" height="30" valign="middle" class="LeftTD" align="right">邮件附件列表:</td>
<td valign="middle"><input type="button" value="增加附件" class="Button" onclick="addFile()" id="Button1" />
</td>
</tr>
<tr>
<td width="150" height="30" valign="middle" class="LeftTD" align="right"></td>
<td valign="middle"><p id="fileList"><input type="file" size="50" name="file" class="Button" /></p>
</td>
</tr>
后台代码:
HttpFileCollection fileList = HttpContext.Current.Request.Files;
for(int i = 0; i < fileList.Count; i++)
{ ///添加单个附件
HttpPostedFile file = fileList[i];
if(file.FileName.Length <= 0 || file.ContentLength <= 0) continue;
Attachment attachment = new Attachment(file.FileName);
mail.Attachments.Add(attachment);
size += file.ContentLength;
}
<script language="javascript" type="text/javascript">
function addFile()
{
var filebutton = '<br><input type="file" size="50" name="file" class="Button" />';
document.getElementById('FileList').insertAdjacentHTML("beforeEnd",filebutton);
}
</script>
页面中:
<tr>
<td width="150" height="30" valign="middle" class="LeftTD" align="right">邮件附件列表:</td>
<td valign="middle"><input type="button" value="增加附件" class="Button" onclick="addFile()" id="Button1" />
</td>
</tr>
<tr>
<td width="150" height="30" valign="middle" class="LeftTD" align="right"></td>
<td valign="middle"><p id="fileList"><input type="file" size="50" name="file" class="Button" /></p>
</td>
</tr>
后台代码:
HttpFileCollection fileList = HttpContext.Current.Request.Files;
for(int i = 0; i < fileList.Count; i++)
{ ///添加单个附件
HttpPostedFile file = fileList[i];
if(file.FileName.Length <= 0 || file.ContentLength <= 0) continue;
Attachment attachment = new Attachment(file.FileName);
mail.Attachments.Add(attachment);
size += file.ContentLength;
}
相关文章推荐
- 同时引入多个同类型文件的技巧
- makefile同时指定多个同名头文件/库文件, 那实际到底采用的是哪个呢?
- 在 ASP.NET 2.0 中上载文件(多个文件同时上传)--青蛙非王子(lostfrog)
- 如何同时打印多个DevExpress报表文件?
- 确保多个进程同时写入同一个文件成功(php)
- 修改内核文件使系统同时支持多个特定usbserial设备
- Android 多线程断点续传同时下载多个大文件
- 如何同时打印多个DevExpress报表文件?
- C# 1.Winform 同时修改多个config文件2.实时监测某程序运行状态(多线程),未启动时,自启。
- sharepoint不能上载多个文件
- Aandroid 多线程断点续传同时下载多个大文件
- android 多线程同时下载多个较大文件
- pads布局布线技巧(【PCB文件中显示引脚号】 【敷铜】 【显示网络名】 【高亮网络】 【修改PCB中文本的尺寸】 【同时修改多个文本(对象)的尺寸(属性) 让集中在一起的元件散开)
- php如何确保多个进程同时写入一个文件成功
- 在文件中同时grep多个关键字
- MediaPlayer支持较大音乐文件的播放,但资源占用率高,延迟时间长,且不支持多个音频同时播放。
- java 上传文件代码,支持中文文件名和中文文件内容,可以同时提交多个参数
- tomcat共享bin目录,配置文件私有,方便多个项目同时部署做依赖调试。
- 使用ajaxFileUpload上传文件流至服务器,同时提交多个参数
- 如何实现将数据同时保存到两个数据表,使得同一次提交多个文件的文件ID号相同