Upload a binary file to a database image field

Source: Internet
Author: User

// Save the uploaded file
If (myfile. postedfile! = NULL)
{
If (myfile. postedfile. filename. Length = 0)
{
This. lbscript. Text = "<script language = JavaScript> alert ('Select Upload File! '); </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 (), ACC. simpletanslate (this. textbox1.text), int32.parse (this. dropdownlist1.selecteditem. value), system. datetime. now, imgbinarydata, ACC. simpletanslate (this. textbox2.text ));

/// <Summary>
/// Save the objectdict File
/// </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. deleettings ["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 ("[work log] The form is added successfully! Details: content = {0 }. ", Content );
Return true;

}
}
Catch (exception ex)
{
Strlog = string. Format ("[work log] The form is added successfully! Details: content = {0 }. ", Content );

Return false;
}
Finally
{
// Write logs
Pmmsweb. dataaccessor. commonfun. Logger. writeuserlog (strlog );
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.