Using system. IO;
Byte [] file = NULL;
If (upf1.postedfile. contentlength> 0)
{
String [] filesplite = upf1.postedfile. filename. Split ('//'); // get the file name
Fn = filesplite [filesplite. Length-1];
FT = upf1.postedfile. contenttype;
String faan = server. mappath (".") + "// upload //" + FN;
Upf1.postedfile. saveas (faan );
Fileinfo Fi = new fileinfo (faan );
Filestream FS = Fi. openread ();
Byte [] bytes = new byte [fs. Length];
FS. Read (bytes, 0, convert. toint32 (FS. Length ));
File = bytes;
FS. Flush ();
FS. Close ();
FI = NULL;
FI = new fileinfo (faan );
Fi. Delete ();
FI = NULL;
}
String conn = configurationmanager. receivettings ["oracle9iconnstr"];
Oracleconnection myconnection = new oracleconnection (conn );
Oraclecommand mycommand = new oraclecommand ();
Mycommand. Connection = myconnection;
Oracledataadapter objdataadapter = new oracledataadapter ();
Objdataadapter. selectcommand = mycommand;
Dataset sett = new dataset ();
String str12 = "select * From sz_disk where fpath = '" + request. form ["fpath"]. trim (). tostring () + "'and fname ='" + request. form ["fname"]. trim (). tostring (). replace ("'", "") + "' and ID <>" + ID;
Mycommand. commandtext = str12;
Objdataadapter. Fill (sett, "C ");
If (sett. Tables ["C"]. Rows. Count> 0)
{
Response. Write ("<SCR" + "ept Language = JavaScript> alert ('This file already exists! '); </Scr "+" IPT> ");
Return;
}
Oraclecommandbuilder cb = new oraclecommandbuilder (objdataadapter );
String str2 = "select * From sz_disk where id =" + ID;
Mycommand. commandtext = str2;
Objdataadapter. Fill (sett, "B ");
Datarow DR1 = sett. Tables ["B"]. Rows [0];
// DR1 ["fpath"] = request. Form ["fpath"]. Trim (). tostring ();
If (request. Form ["fname"]. Trim (). tostring (). Replace ("'","")! = "")
{
DR1 ["fname"] = request. Form ["fname"]. Trim (). tostring (). Replace ("'","");
}
Else
{
DR1 ["fname"] = system. dbnull. value;
}
If (request. Form ["keyword"]. Trim (). tostring ()! = "")
{
DR1 ["keyword"] = request. Form ["keyword"]. Trim (). tostring ();
}
Else
{
DR1 ["keyword"] = system. dbnull. value;
}
// DR1 ["response"] = request. Form ["response"]. Trim (). tostring ();
DR1 ["ctime"] = datetime. now;
If (file! = NULL)
{
DR1 ["filedata"] = file;
DR1 ["filetype1"] = ft;
DR1 ["FILENAME"] = FN;
}
DR1 ["fileimage"] = request. Form ["fi"]. tostring ();
Switch (request. Form ["fi"]. tostring ())
{
Case "doc.jpg ":
DR1 ["filetype"] = "Word Document ";
Break;
Case "ppt.jpg ":
DR1 ["filetype"] = "Demo ";
Break;
Case "htm.jpg ":
DR1 ["filetype"] = "webpage Files ";
Break;
Case "swf.jpg ":
DR1 ["filetype"] = "Flash file ";
Break;
Case "jpg.jpg ":
DR1 ["filetype"] = "image files ";
Break;
Case "txt.jpg ":
DR1 ["filetype"] = "text file ";
Break;
Case "mdb.jpg ":
DR1 ["filetype"] = "Access Database ";
Break;
Case "xls.jpg ":
DR1 ["filetype"] = "Excel document ";
Break;
Case "mp3.jpg ":
DR1 ["filetype"] = "audio file ";
Break;
Case "zip.jpg ":
DR1 ["filetype"] = "compressed file ";
Break;
Case "png.jpg ":
DR1 ["filetype"] = "fireworks file ";
Break;
Default:
DR1 ["filetype"] = "unknown type ";
Break;
}
If (request. Form ["content"]. Trim (). tostring (). Replace ("'","")! = "")
{
DR1 ["content"] = request. Form ["content"]. Trim (). tostring (). Replace ("'","");
}
Else
{
DR1 ["content"] = system. dbnull. value;
}
// Response. write ("<SCR" + "ept> alert ('" + session ["name"]. tostring () + "'); </scr" + "IPT> ");
// Sett. Tables ["B"]. Rows. Add (DR1 );
Objdataadapter. Update (sett, "B ");
Sett. Clear ();
Response. Write ("<SCR" + "ept Language = JavaScript> alert ('saved successfully! '); Window. opener. Location. Reload (); window. Opener = ''; window. Close (); </scr" + "ERT> ");
Public void file_click (Object sender, system. Web. UI. imageclickeventargs E)
{
String conn = configurationmanager. receivettings ["oracle9iconnstr"];
String strsql1 = "select * From sz_disk where id =" + ID;
// Response. Write (strsql1 );
// Response. End ();
Oracleconnection myconnection = new oracleconnection (conn );
Oraclecommand mycommand = new oraclecommand ();
Mycommand. Connection = myconnection;
Oracledataadapter objdataadapter = new oracledataadapter ();
Objdataadapter. selectcommand = mycommand;
Dataset objectset1 = new dataset ();
Mycommand. commandtext = strsql1;
Objdataadapter. Fill (objectset1, "B ");
Datarow DR1 = objectset1.tables ["B"]. Rows [0];
Response. Clear ();
// Byte [] file = NULL;
// File = (byte []) DR1 ["filedata"];
Response. contenttype = DR1 ["filetype1"]. tostring ();
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode (DR1 ["FILENAME"]. tostring (), system. text. encoding. utf8 ));
Response. binarywrite (byte []) DR1 ["filedata"]);
Response. End ();
}