using CY.Infrastructure.Common;
|
using CY.Infrastructure.Logging;
|
using CY.SQLDAL;
|
using System;
|
using System.Collections.Generic;
|
using System.Data.SqlClient;
|
using System.Linq;
|
using System.Web;
|
using System.Web.UI;
|
using System.Web.UI.WebControls;
|
using static CY.WebForm.MainPage;
|
using CY.Model.OA;
|
using CY.WebForm.Helper;
|
using CY.Infrastructure.Query;
|
using System.IO;
|
using CY.Infrastructure.Configuration;
|
using System.Collections;
|
using System.Globalization;
|
|
namespace CY.WebForm.Pages.business
|
{
|
public partial class WorkBookUpLoad : BasePage
|
{
|
|
|
/// <summary>
|
/// 选择文件
|
/// </summary>
|
List<HttpFileCollection> SelFile { set; get; }
|
/// <summary>
|
/// 合同附件集合
|
/// </summary>
|
List<OA_CorporateClientsContract> fileDataList { set; get; } = new List<OA_CorporateClientsContract>();
|
|
|
|
/// <summary>
|
/// 附件个数
|
/// </summary>
|
public int FileCount { get; set; }
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
|
if (!IsPostBack)
|
HideKeyid.Value = Request["Keyid"];
|
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void btn_Submit_Click(object sender, EventArgs e)
|
{
|
string ssss = HideKeyid.Value;
|
|
var files = Request.Files;
|
if (files.Count <= 0)
|
return;
|
// return;
|
HttpPostedFile file = null;
|
|
|
|
for (int i = 0; i < files.Count; i++)
|
{
|
|
if (files.Keys[i] == "filesel")
|
{
|
file = files[i];
|
if (file.ContentLength == 0)
|
{
|
return;
|
}
|
|
break;
|
}
|
|
}
|
|
|
string WebDomain = ConfigurationSetting.TuPianLuJing;
|
//根目录路径,相对路径
|
String savePath = "/images/WorkBook/" + DateTime.Now.ToString("yyyyMMdd") + "/";
|
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
|
String saveUrl = ConfigurationSetting.TuPianLuJing.TrimEnd('/') + "/images/WorkBook/" + DateTime.Now.ToString("yyyyMMdd") + "/";
|
|
string fileTypes = "gif,jpg,jpeg,png,bmp";
|
double maxSize = 2 * 1024 * 1024;
|
|
|
string dirPath = Server.MapPath("~" + savePath);
|
if (!Directory.Exists(dirPath))
|
{
|
Directory.CreateDirectory(dirPath);
|
}
|
|
string fileName = file.FileName;
|
string fileExt = Path.GetExtension(fileName).ToLower();
|
|
ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(','));
|
|
if (file.InputStream == null || file.InputStream.Length > maxSize)
|
{
|
JavaScript.MessageBox("上传文件大小超过限制", this);
|
|
}
|
|
if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
|
{
|
JavaScript.MessageBox("上传文件扩展名是不允许的扩展名", this);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
{
|
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
|
string filePath = dirPath + newFileName;
|
file.SaveAs(filePath);
|
string fileUrl = saveUrl + newFileName;
|
|
JavaScript.MessageBoxfuzhi("上传文件成功", this,true, ssss, fileUrl);
|
//JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
|
}
|
catch (Exception )
|
{
|
JavaScript.MessageBox("上传文件失败", this);
|
// JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
|
|
}
|
|
|
// CY.WebForm.cs.UploadCS.Upload(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString() + fileName)
|
|
|
//var files = Request.Files;
|
//for (int iFile = 0; iFile < files.Count; iFile++)
|
//{
|
// ///'检查文件扩展名字
|
// HttpPostedFile postedFile = files[iFile];
|
// string fileName, fileExtension;
|
// fileName = System.IO.Path.GetFileName(postedFile.FileName);
|
// if (fileName != "")
|
// {
|
// fileExtension = System.IO.Path.GetExtension(fileName);
|
// //strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
|
// //strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
|
// //strMsg.Append("上传文件的文件名:" + fileName + "<br>");
|
// //strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
|
// ///'可根据扩展名字的不同保存到不同的文件夹
|
// ///注意:可能要修改你的文件夹的匿名写入权限。
|
// ///
|
|
// // postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString()+ fileName);
|
|
|
// }
|
//}
|
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|