欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)】,下面是详细的讲解!
asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)
/// <summary>
/// 文件上传后台处理页面
/// </summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType="text/plain";
context.Response.Charset="utf-8";
try
{
string guid=context.Request.QueryString["guid"];
string folder=context.Request["folder"];
//LogTextHelper.Info(folder);
HttpPostedFile file=context.Request.Files["Filedata"];
if (file !=null)
{
string oldFileName=file.FileName;//原文件名
int size=file.ContentLength;//附件大小
string extenstion=oldFileName.Substring(oldFileName.LastIndexOf(".") + 1);//后缀名
string newFileName=GetNewFileName(oldFileName);//生成新文件名
//LogTextHelper.Info(newFileName);
#region 上传到远程服务器
//FileServerManage fsw=new FileServerManage();
//string uploadFilePath="/" + newFileName;
//if (!string.IsNullOrEmpty(folder))
//{
// uploadFilePath=string.Format("/{0}/{1}", folder, newFileName);
//}
//bool uploaded=fsw.UploadFile(file.InputStream, "/" + folder + "/" + newFileName);
#endregion
#region 本地服务器上传
AppConfig config=new AppConfig();
string uploadFiles=config.AppConfigGet("uploadFiles");
if (string.IsNullOrEmpty(uploadFiles))
{
uploadFiles="uploadFiles";
}
if (!string.IsNullOrEmpty(folder))
{
uploadFiles=Path.Combine(uploadFiles, folder);
}
string uploadPath=Path.Combine(HttpContext.Current.Server.MapPath("/"), uploadFiles);
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string newFilePath=Path.Combine(uploadPath, newFileName);
LogTextHelper.Info(newFilePath);
file.SaveAs(newFilePath);
bool uploaded=File.Exists(newFilePath);
#endregion
if (uploaded)
{
#region 文件保存成功后,写入附件的数据库记录
//AttachmentInfo attachmentInfo=new AttachmentInfo();
//attachmentInfo.EditorTime=DateTime.Now;
//attachmentInfo.FileExtend=extenstion;
//attachmentInfo.FileName=folader + "/" + newFileName;
//attachmentInfo.OldFileName=oldFileName;
//attachmentInfo.Size=size;
//attachmentInfo.Guid=guid;
//BLLFactory<Attachment>.Instance.Insert(attachmentInfo);
#endregion
}
}
else
{
LogTextHelper.Error("上传文件失败");
}
}
catch (Exception ex)
{
LogTextHelper.Error("上传文件失败", ex);
throw;
}
}
/// <summary>
/// 获取新的名称 比如:aa.jpg转化为aa(20090504).jpg
/// </summary>
/// <param name="fileName">文件名称[aa.jpg]</param>
/// <returns>新的文件名称</returns>
public static string GetNewFileName(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return string.Empty;
//文件后缀名
string extenstion=fileName.Substring(fileName.LastIndexOf(".") + 1);
string name=fileName.Substring(0, fileName.LastIndexOf(".")) + "(" + DateTime.Now.ToFileTime() + ")";
string newFileName=name + "." + extenstion;
return newFileName;
}
public bool IsReusable
{
get
{
return false;
}
}
}
关于asp.net(c#)开发中的文件上传组件uploadify的使用方法(带进度条)的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
