.NET上传图片的方法(使用控件FILEUpdate)
来源:互联网 发布:mac文件夹隐藏 编辑:程序博客网 时间:2024/06/04 20:13
net使用FileUpLoad控件上传文件2008-04-23 15:24单个文件的上传:保存到上传服务器指定目录: FileUpload1.Save(Server.MapPath("/upfiles/upload/") +FileUpload1.FileName);得到上传文件的文件名(含上传本地路径):FileUpload1.PostedFile.FileName;得到上传文件的大小:FileUpload1.PostedFile.ContentLength;得到上传文件上传类型:FileUpload1.PostedFile.ContentType;得到上传文件扩展名:System.IO.Path.GetExtension(FileUpload1.FileName);得到上传文件名:FileUpload1.FileName;同时多个文件的上传: 方法是将 System.IO 类导入到 ASP.NET 页中,然后使用 HttpFileCollection 类捕获通过 Request 对象发送来的所有文件。该方法使您可以从一个页面上载所需数量的文件。使用 HttpFileCollection 类和 Request.Files 属性使您可以控制从该页上载的所有文件。(你可以在上传页面上放N个FileUpload控件)得到上传的文件名:System.IO.Path.GetFileName(FileUpload1.FileName);//Request.Files得到的多部分MIME格式的由客户端上载的文件的集合都是包含上传本地完整路径的。
protected void Button1_Click(object sender, EventArgs e )
{
//上传单张
//string a = Server.MapPath(@"\Web\image\");
//FileUpload1.SaveAs(Server.MapPath("/Web/image/" + FileUpload1.FileName));
//上传多张
string filepath = Server.MapPath("/upfiles/upload/");
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Label1.Text += "File #" + (i + 1) +
"";
Label1.Text += "File Content Type: " +
userPostedFile.ContentType + "";
Label1.Text += "File Size: " +
userPostedFile.ContentLength + "kb";
Label1.Text += "File Name: " +
userPostedFile.FileName + "";
userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName));
Label1.Text += "Location where saved: " +
filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName) + "";
}
}
catch (Exception Ex)
{
Label1.Text += "Error: " + Ex.Message;
}
}
}
protected void Button1_Click(object sender, EventArgs e )
{
//上传单张
//string a = Server.MapPath(@"\Web\image\");
//FileUpload1.SaveAs(Server.MapPath("/Web/image/" + FileUpload1.FileName));
//上传多张
string filepath = Server.MapPath("/upfiles/upload/");
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Label1.Text += "File #" + (i + 1) +
"";
Label1.Text += "File Content Type: " +
userPostedFile.ContentType + "";
Label1.Text += "File Size: " +
userPostedFile.ContentLength + "kb";
Label1.Text += "File Name: " +
userPostedFile.FileName + "";
userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName));
Label1.Text += "Location where saved: " +
filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName) + "";
}
}
catch (Exception Ex)
{
Label1.Text += "Error: " + Ex.Message;
}
}
}
- .NET上传图片的方法(使用控件FILEUpdate)
- ASP.NET使用FileUpLoad控件上传图片前预览图片
- ASP.NET上传图片的简单方法
- asp.net 使用FileUpload控件上传并显示图片
- 在asp.Net中使用fileuplod控件实现上传图片的功能
- 在asp.Net中使用fileuplod控件实现上传图片的功能
- asp.net 2.0 上传控件的使用
- asp.net 2.0上传控件的使用
- asp.net 2.0 上传控件的使用
- asp.net 上传控件的使用
- Yii上传图片,上传文件,yii控件activefilefield的使用
- 使用jspSmartUpload控件上传图片
- Asp.net 图片上传方法
- asp.net图片上传-简单实用(VS2008 FileUpload控件)
- Asp.net通过FileUpLoad控件上传图片
- .net使用Jquery上传图片
- 使用客户端的File Field控件上传图片
- 使用客户端的File Field控件上传图片
- SQL— CONCAT(字符串连接函数)
- linux指令学习(一)
- 天气Api
- c语言以字符形式实现文件的读写操作
- ASP.NET弹框后页面跳转
- .NET上传图片的方法(使用控件FILEUpdate)
- lua栈理解及lua和C++的数据交换API介绍
- C++ 类中定义常量的方法
- 利用本地iso文件创建yum源
- Oracle笔记_内置函数
- undo 表空间使用案例分析(使用率100%,enq:US-contention,释放undo)
- C语言求其文件名长度DEMO
- Jquery调用AJAX的方法
- valgrind