Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Using system. configuration;
Using system. IO;
Namespace SZ
{
/// <Summary>
/// Summary of upfile.
/// </Summary>
Public class UPF: system. Web. UI. Page
{
Protected system. Web. UI. htmlcontrols. htmlinputfile upf1;
Private void page_load (Object sender, system. eventargs E)
{
}
Public void submit_click (Object sender, system. eventargs E)
{
If (upf1.postedfile. contentlength> 0)
{
String [] filesplite = upf1.postedfile. filename. Split ('//'); // get the file name
String fn = filesplite [filesplite. Length-1];
String Ft = upf1.postedfile. contenttype;
Fileinfo Fi = new fileinfo (upf1.postedfile. filename );
Filestream FS = Fi. openread ();
Byte [] bytes = new byte [fs. Length];
FS. Read (bytes, 0, convert. toint32 (FS. Length ));
String conn = configurationsettings. receivettings ["myconn9"];
Sqlconnection Cn = new sqlconnection (conn );
Sqlcommand CM = new sqlcommand ();
Cm. Connection = cn;
Cm. commandtype = commandtype. text;
If (CN. State = 0) Cn. open ();
Cm. commandtext = "insert into sz_file (filename, filetype, filedata) values ('" + FN + "', '" + ft + "', @ file )";
Sqlparameter spfile = new sqlparameter ("@ file", sqldbtype. Image );
Spfile. value = bytes;
Cm. Parameters. Add (spfile );
Cm. executenonquery ();
}
}
Public void down_click (Object sender, system. eventargs e ){
String conn = configurationsettings. receivettings ["myconn9"];
String strsql = "select * From sz_file ";
Sqlconnection myconnection = new sqlconnection (conn );
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Sqldataadapter objdataadapter = new sqldataadapter ();
Objdataadapter. selectcommand = mycommand;
Dataset objectset = new dataset ();
Mycommand. commandtext = strsql;
Objdataadapter. Fill (objectset, "");
Datarow DR = objectset. Tables ["A"]. Rows [0];
Byte [] file = NULL;
File = (byte []) Dr ["filedata"];
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (Dr ["FILENAME"]. tostring (), system. text. encoding. utf8 ));
Response. contenttype = Dr ["filetype"]. tostring ();
Response. binarywrite (File );
}
# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}