ASPxUploadControl使用

ASPxUploadControl
 
/*******************快速使用*************************/
定好保存路径
设置控件的fileuploadcomplete事件
 
using System.IO;
using DevExpress.Web.ASPxUploadControl; 
 #region 上传文件
    ///
    /// 保存上传文件
    ///
    ///
    ///
    protected string SavePostedFiles(UploadedFile uploadedFile)
    {
        //保存至服务器上的路径
        fangqm.Netbank.Core.Savepath savepath = new fangqm.Netbank.Core.Savepath();
        UploadDirectory = savepath.getuploadfileSavePath(DateTime.Now.ToShortDateString());
        if (!Directory.Exists(Server.MapPath(UploadDirectory)))
        {
            Directory.CreateDirectory(Server.MapPath(UploadDirectory));
        }
        string ret = "";
        if (uploadedFile.IsValid)
        {  //显示进度
            FileInfo fileInfo = new FileInfo(uploadedFile.FileName);
            string resFileName = MapPath(UploadDirectory) + fileInfo.Name;
            uploadedFile.SaveAs(resFileName);
            string fileLabel = fileInfo.Name;
            string fileType = uploadedFile.PostedFile.ContentType.ToString();
            string fileLength = uploadedFile.PostedFile.ContentLength / 1024 + "K";
            ret = string.Format("{0} ({1}){2}|{3}", fileLabel, fileType, fileLength, fileInfo.Name);
        }
        return ret;
    }
    protected void ASPxUploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
    {
        try
        {
            e.CallbackData = SavePostedFiles(e.UploadedFile);
        }
        catch (Exception ex)
        {
            e.IsValid = false;
            e.ErrorText = ex.Message;
        }
    }
    #endregion
ValidationSettings属性下,可以设置上传文件大小(字节),文件类型,文件扩展名
设置上传文件大小(字节)MaxFileSize="4000000"
文件类型     AllowedContentTypes="image/jpeg,image/gif,image/pjpeg"
文件扩展名   AllowedFileExtensions=".jpg,.jpeg,.jpe,.gif"
 
如果使用中发现取不到服务器控件如aspxtextbox值,可以将其FileUploadMode="OnPageLoad"即可
 
File Type

  MIME Content Type

  .txt (text document)text/plain.pdf (PDF document)application/pdf.doc (MS Word document)application/msword.docx (MS Word 2007 document)application/vnd.openxmlformats-officedocument.wordprocessingml.document.xls (MS Excel document)application/vnd.ms-excel.xlsx (MS Excel 2007 document)application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.jpeg or .jpg (JPEG image)image/jpeg,image/pjpeg.gif (GIF image)image/gif.png (PNG image)image/png,image/x-png.bmp (BMP image)image/bmp.zip (ZIP archive)application/zip
 
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-670868/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23109131/viewspace-670868/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值