代码改变世界

上传文件基础类方法

2013-10-19 01:06  sql_manage  阅读(217)  评论(0编辑  收藏  举报

 private void FileUpload(System.Web.UI.WebControls.FileUpload FileUploadControl,string savePath)
        {
            try
            {
                if (FileUploadControl.HasFile)
                {
                    string fileName = FileUploadControl.FileName;
                    string fileExtendName = fileName.Substring(fileName.LastIndexOf('.'));
                    //过滤文件后缀
                    if (fileExtendName.ToLower() == "xls" || fileExtendName.ToLower() == "xlsx")
                    {
                        FileUploadControl.PostedFile.SaveAs(Server.MapPath(savePath));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }