上传二进制文件到数据库image类型字段
//保存上传文件
if(myFile.PostedFile!=null)
{
if (myFile.PostedFile.FileName.Length==0)
{
this.lbScript.Text = "<script language=javascript>alert('请选择上传文件!');</script>";
return;
}
imgStream=myFile.PostedFile.InputStream ;
imgLen=myFile.PostedFile.ContentLength;
imgfiletype="DOC";
imgBinaryData=new byte[imgLen];
imgStream.Read(imgBinaryData,0,imgLen);
}
else
{
imgBinaryData=new byte[0];
}
bool result = InsertLog(Int32.Parse(Session["UserID"].ToString()),myc.SimpleTanslate(this.TextBox1.Text),Int32.Parse(this.DropDownList1.SelectedItem.Value),System.DateTime.Now,imgBinaryData,myc.SimpleTanslate(this.TextBox2.Text));
/// <summary>
/// 保存ObjectDict文件
/// </summary>
/// <param name="filename"></param>
/// <param name="MediaTypeid"></param>
/// <param name="imgBinaryData"></param>
/// <param name="imgfiletype"></param>
/// <param name="objectid"></param>
/// <returns></returns>
public static bool InsertLog(int userID,string content,int typeID,DateTime date,byte[] imgBinaryData,string note)
{
string strLog = null;
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DB_PMMS_String"]);
string sql="PMMSOA_Log_SaveLog";
SqlParameter[] paras = new SqlParameter[6];
paras[0] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@UserID",userID);
paras[1] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@Content",content);
paras[2] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@TypeID",typeID);
paras[3] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@Date",date);
paras[4] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@Attachment",imgBinaryData);
paras[5] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@Note",note);
//paras[4] =PMMSWeb.DataAccessor.CommonFun.SqlHelper.NewParameter("@Note",objectid);
SqlCommand cmd =PMMSWeb.DataAccessor.CommonFun.SqlHelper.CreateCommand(sql,cn,CommandType.StoredProcedure,paras);
try
{
using(cn)
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
strLog = string.Format("[工作日志]增加表单成功!详细信息:Content={0}。",content);
return true;
}
}
catch(Exception ex)
{
strLog = string.Format("[工作日志]增加表单成功!详细信息:Content={0}。",content);
return false;
}
finally
{
//写入日志
PMMSWeb.DataAccessor.CommonFun.Logger.WriteUserLog(strLog);
}
}