using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

using Security;
namespace Security
{
	public partial class uploadFile : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e){ 
			
		}

		protected void btnUploadFile_Click(object sender, EventArgs e)
		{
			if (fileUpload.HasFile)
			{
				///创建数据连接对象：
				MysqlHelp mh = new MysqlHelp();
				///查询数据库
				DataTable dt=new DataTable();
				dt = mh.GetDatabysql("Select * From Preference4DeepSoon");
				string uploadFileDir = "/UploadFile/";
				if(dt.Rows.Count > 0 ){
					uploadFileDir = dt.Rows[0]["uploadFileDir"].ToString();
				}
			
				string fileContentType = fileUpload.PostedFile.ContentType;
				string name = fileUpload.PostedFile.FileName;  /// 客户端上传文件路径
				FileInfo file = new FileInfo(name);
				string FileType = file.Name.Substring(file.Name.LastIndexOf("."));                   ///文件后缀名   
				string fileName = DateTime.Now.ToString("yyyyMMddhhmmssms")+FileType;                /// 上传的文件名称
				string webFilePath = Server.MapPath(uploadFileDir + fileName);        /// 服务器端文件路径
				if (!File.Exists(webFilePath))
				{
					try
					{
						fileUpload.SaveAs(webFilePath);       /// 保存原始文件
						Response.Write("<script type='text/javascript'>");
						Response.Write("window.parent.document.getElementById('fileHref').value = '" + uploadFileDir + fileName+"'");
						Response.Write("</script>");
					}catch (Exception ex){}
				}
			}

		}
		
	}
}