Click to upload
Code:
- Protected void imgbtnup_click (Object sender, imageclickeventargs E)
- {
- // String Path = fileupload1.postedfile. filename;
- // String imgname = path. substring (path. lastindexof ("//") + 1 );
- // String serverpath = server. mappath ("Dropbox/") + imgname;
- // Fileupload1.postedfile. saveas (serverpath );
- Try
- {
- If (fileupload1.postedfile. filename! = "")
- {
- String filepath = fileupload1.postedfile. filename; // retrieve the index of the last "." In the file name (inclusive path ).
- String filenames = filepath. substring (filepath. lastindexof ("//") + 1 );
- String fileextend = filepath. substring (filepath. lastindexof (".") + 1 );
- String filesize = fileupload1.postedfile. contentlength. tostring ();
- If (! (Fileextend = "xls" | fileextend = "xls" | fileextend = "Doc" | fileextend = "Doc" | fileextend = "TXT" | | fileextend = "TXT" | fileextend = "RAR" | fileextend = "RAR "))
- {
- Bll. Pub. Show (this, "the file format is not supported. Please pack the file to be uploaded! ");;
- Return;
- }
- String serverpath = server. mappath ("Dropbox/") + filenames;
- Fileupload1.postedfile. saveas (serverpath );
- Mdropbox. upname = filenames;
- Mdropbox. upsize = convert. toint32 (filesize );
- Mdropbox. uptime = datetime. now;
- Mdropbox. upurl = serverpath;
- // Mdropbox. uid
- Bdropbox. Add (mdropbox );
- Bll. Pub. Show (this, "the file is uploaded successfully! ");
- }
- }
- Catch
- {
- Bll. Pub. Show (this, "add error! ");
- }
- }
Explanation: fileupload1 upload Control name
Row 33 calls public methods and has previously written student.csdn.net/space.php
27 rows add method:
Code:
- /// <Summary>
- /// Add a data entry
- /// </Summary>
- Public int add (model. tbdropbox Model)
- {
- Int rowsaffected;
- Sqlparameter [] parameters = {
- New sqlparameter ("@ upid", sqldbtype. Int, 4 ),
- New sqlparameter ("@ upname", sqldbtype. nvarchar, 100 ),
- New sqlparameter ("@ uptime", sqldbtype. datetime ),
- New sqlparameter ("@ upurl", sqldbtype. nvarchar, 200 ),
- New sqlparameter ("@ uid", sqldbtype. Int, 4 ),
- New sqlparameter ("@ upsize", sqldbtype. Int, 4 )};
- Parameters [0]. Direction = parameterdirection. output;
- Parameters [1]. value = model. upname;
- Parameters [2]. value = model. uptime;
- Parameters [3]. value = model. upurl;
- Parameters [4]. value = model. uid;
- Parameters [5]. value = model. upsize;
- Dbhelpersql. runprocedure ("tbdropbox_add", parameters, out rowsaffected );
- Return (INT) parameters [0]. value;
- }
21 rows of "tbdropbox_add" stored in SQL
Code:
- Create procedure [DBO]. [tbdropbox_add]
- @ Upid int output,
- @ Upname nvarchar (100 ),
- @ Uptime datetime,
- @ Upurl nvarchar (200 ),
- @ Uid int,
- @ Upsize int
- As
- Insert into [tbdropbox] (
- [Upname], [uptime], [upurl], [uid], [upsize]
- ) Values (
- @ Upname, @ uptime, @ upurl, @ uid, @ upsize
- )
- Set @ upid =@@ identity
- Go