Basf_TCC7/HJGL/FineUIPro.Web/FileManage/Save.aspx.cs

112 lines
4.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.FileManager
{
public partial class Save : System.Web.UI.Page
{
public string url, newofficetype,filetype, readURL,typeFlag;
public string txtFileId, txtFileCode, txtFileName, drpBigType, drpSmallType;//定义表单数据
protected void Page_Load(object sender, EventArgs e)
{
txtFileId = Request.Form["txtFileId"];//获取文件ID
txtFileCode = Request.Form["txtFileCode"];//获取已有文件的名称
txtFileName = Request.Form["txtFileName"];//获取文件的标题
drpBigType = Request.Form["drpBigType"];//获取文件另存为格式类型
filetype = Request.Form["filetype"];//获取当前文件的文件格式
drpSmallType = Request.Form["drpSmallType"];
typeFlag = Request.Form["typeFlag"];
saveoffice();
}
//保存文档为office
public void saveoffice()
{
System.Web.HttpFileCollection uploadFiles = Request.Files;
System.Web.HttpPostedFile theFile;
bool isNewRecord = false;
if ((txtFileId.Length == 0) || (txtFileId.Trim().Length == 0))
{
isNewRecord = true;
}
else
{
isNewRecord = false;
}
if (uploadFiles.Count == 0)
{
Response.Write("没有文件上传!");
return;
}
else
{
SqlConnection conn = new SqlConnection(BLL.Funs.ConnString);
if (conn.State == ConnectionState.Closed) conn.Open();
try
{
for (int i = 0; i < uploadFiles.Count; i++)
{
theFile = uploadFiles[i];
int flieLength = theFile.ContentLength;
Stream fs = theFile.InputStream;
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, flieLength);
if (uploadFiles.GetKey(i).ToUpper() == "EDITFILE")//上传文档控件中的文档
{
string strcmd = "";
SqlCommand objCommand = new SqlCommand(strcmd, conn);
if (typeFlag == "00")
{
objCommand.Parameters.Add("@FileCode", System.Data.SqlDbType.NVarChar).Value = txtFileCode;
objCommand.Parameters.Add("@FileName", System.Data.SqlDbType.NVarChar).Value = txtFileName;//
objCommand.Parameters.Add("@FileSize", System.Data.SqlDbType.NVarChar).Value = theFile.ContentLength;
objCommand.Parameters.Add("@FileType", System.Data.SqlDbType.NVarChar).Value = filetype;
objCommand.Parameters.Add("@BigType", System.Data.SqlDbType.NVarChar).Value = drpBigType;
objCommand.Parameters.Add("@SmallType", System.Data.SqlDbType.VarChar).Value = drpSmallType;
objCommand.Parameters.Add("@FileDate", System.Data.SqlDbType.DateTime).Value = DateTime.Now;
objCommand.Parameters.Add("@FileCreate", System.Data.SqlDbType.NVarChar).Value = ((Model.Sys_User)Session["CurrUser"]).UserId;
objCommand.Parameters.Add("@FileContent", System.Data.SqlDbType.Image).Value = bytes;
}
else
{
objCommand.Parameters.Add("@FileContent", System.Data.SqlDbType.Image).Value = bytes;
}
if (isNewRecord)
{
txtFileId = objCommand.ExecuteScalar().ToString();
}
else
{
objCommand.ExecuteNonQuery();
}
//Response.Write("ID:" + txtFileId + "</br>");
//Response.Write("Files: " + txtFileName + "<br>");
//Response.Write("Size: " + theFile.ContentLength.ToString() + " bytes<br>");
}
}
}
finally
{
conn.Close();
}
}
}
}
}