Spiga

【原创】Coolite异步上传图片

2010-09-21 08:49 by 冷风旋, 263 visits, 收藏, 编辑
异步上传图片
Coolite.Ext.Web.FileUploadField uploadControl = ((Coolite.Ext.Web.FileUploadField)this.tbMain.FindControl(ControlsID.imageUpload));
//图片路径
string strFileName = uploadControl.FileName;

DateTime Now
= DateTime.Now;

string FileName = "Parts" + Now.ToString("yyyyMMddHHmmssffff");

string FilePath = "~/UploadFile/ConstructImage/" + FileName + System.IO.Path.GetExtension(strFileName);

try
{
System.Web.HttpFileCollection _files
= System.Web.HttpContext.Current.Request.Files;

for (System.Int32 _iFile = 0; _iFile < _files.Count; _iFile++)
{
System.Web.HttpPostedFile _postedFile
= _files[_iFile];

if (!string.IsNullOrEmpty(FilePath))
{
if (System.IO.File.Exists(System.Web.HttpContext.Current.Request.MapPath(FilePath)))
{
File.Delete(System.Web.HttpContext.Current.Request.MapPath(FilePath));
}
_postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(FilePath));
}
}
}
catch
{

Coolite.Ext.Web.MessageBox.Config configError
= new Coolite.Ext.Web.MessageBox.Config();
configError.Title
= "上传状态";
configError.Message
= "文件上传有错误,请检查!";
configError.Buttons
= Coolite.Ext.Web.MessageBox.Button.OK;
configError.Icon
= Coolite.Ext.Web.MessageBox.Icon.ERROR;
Coolite.Ext.Web.Ext.Msg.Show(configError);
return;
}


Coolite.Ext.Web.Image uploadImage
= ((Coolite.Ext.Web.Image)this.tbMain.FindControl(ControlsID.uploadImage));
uploadImage.ImageUrl
= FilePath;

this.ImageUrl = @"http://" + Request.Url.Host + ":" + Request.Url.Port.ToString() + Request.ApplicationPath + FilePath.Replace("~", string.Empty);

Session.Add(
"imageUrl", ImageUrl.ToString());

Coolite.Ext.Web.MessageBox.Config config
= new Coolite.Ext.Web.MessageBox.Config();
config.Title
= "上传状态";
config.Message
= "上传成功";
config.Buttons
= Coolite.Ext.Web.MessageBox.Button.OK;
config.Icon
= Coolite.Ext.Web.MessageBox.Icon.INFO;

Coolite.Ext.Web.Ext.Msg.Show(config);
作者:冷风旋
出处:http://zzyn.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 1832237 WirUeZUT474=