ASP.NETÖÐÉÏ´«Îļþµ½Êý¾Ý¿â
SQL½Å±¾£º
CREATE TABLE tblBooksUpload
(
¡¡DocID int NOT NULL IDENTITY Primary Key ,
¡¡DocTitle varchar (200) ,
¡¡Doc image,
¡¡DocType varchar (50) ,
¡¡Entrydate datetime Default GetDate()
)
Ê×ÏÈÎÒÃÇҪʵÏÖÓû§ÔÚä¯ÀÀÆ÷¶Ë×ÔÓÉÑ¡ÔñÎļþ£¬È»ºóÉÏ´«£¬ÕâÀïÓû§Ñ¡ÔñÎļþ£¬µ±È»ÊÇÒªÇó±ê×¼µÄWindows·½Ê½£¬ËùÒÔ£¬ÎÒÃÇÔÚÕâÀïʹÓÃFormµÄFileÎļþ×é¼þÀ´¸øÓû§Ñ¡ÔñÎļþ¡£×¢Ò⣬ÒòΪÉÏ´«Îļþ£¬ËùÒÔ£¬ÔÚFormµÄÊôÐÔÉèÖõÄʱºò£¬ÎÒÃÇÓ¦¸ÃÉèÖÃΪ£ºmultipart/form-data£¬ÕâÑù£¬²Å¿ÉÒÔÕýÈ·ÉÏ´«Îļþ¡£ÏÂÃæÊÇÉÏ´«Ò³ÃæµÄÖ÷Òª´úÂ룺
£¼form id="frmUpload" method="post" enctype="multipart/form-data" runat="server"£¾
£¼span£¾Title£¼/span£¾£¼br£¾
£¼asp:textbox id="txtTitle" runat="server" EnableViewState="False"£¾£¼/asp:textbox£¾
£¼asp:requiredfieldvalidator id="valrTitle" runat="server" ErrorMessage="*
Required" ControlToValidate="txtTitle"£¾* Required£¼/asp:requiredfieldvalidator£¾
£¼br£¾
£¼br£¾
£¼span£¾Docutment to Upload£¼/span£¾£¼br£¾
£¼input id="txtFileContents" type="file" runat="server" NAME="txtFileContents"£¾
£¼br£¾
£¼br£¾
£¼asp:button id="btnSubmit" Text="Submit" Runat="server"£¾£¼/asp:button£¾
£¼/form£¾
½ÓÏÂÀ´£º
int intDocLen = txtFileContents.PostedFile.ContentLength;
byte[] Docbuffer = new byte[intDoclen];
Stream objStream;
objStream = txtFileContents.PostedFile.InputStream;
objStream.Read(Docbuffer,0,intDocLen);
cmdUploadDoc = new SqlCommand("uSP_BooksUploadFile",BooksConn);
cmdUploadDoc.CommandType = CommandType.StoredProcedure;
cmdUploadDoc.Parameters.Add("@Title ",SqlDbType.VarChar,200);
cmdUploadDoc.Parameters.Add("@Doc",SqlDbType.Image);
cmdUploadDoc.Parameters.Add("@DocType",SqlDbType.VarChar,4);
cmdUploadDoc.Parameters[0].Value = txtTitle.Text;
cmdUploadDoc.Parameters[1].Value = Docbuffer;
cmdUploadDoc.Parameters[2].Value = strDocType;
private v
Ïà¹ØÎĵµ£º
1.°²×°ºó
°²×°ÍêMVCºó,VSµÄWEBÏîÄ¿Àï»á³öÏÖÁ½¸öеÄÄ£°æ:
a. ASP.NET MVC 2 WEB Application ʹÓÃÕâ¸öÄ£°å»á¶àÉú³ÉÒ»¸öNUNIT²âÊÔÏîÄ ......
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
&n ......
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="100%">
<param name="movie" value="<%= ResolveUr ......
¡¡¡¡ÓÉÊý¾Ý¿âÇý¶¯µÄWebÓ¦ÓóÌÐò£¬Èç¹ûÐèÒª¸ÄÉÆÆäÐÔÄÜ£¬×îºÃµÄ·½·¨ÊÇʹÓûº´æ¹¦ÄÜ¡£Óû§´ÓÊý¾Ý¿âÖмìË÷Êý¾Ý£¬¿ÉÄÜÊÇWebÓ¦ÓóÌÐòÖÐÖ´ÐÐ×îÂýµÄ²Ù×÷Ö®Ò»¡£ÒòΪÆäÖÐÉæ¼°¶à¸ö»·½Ú£¬ÀýÈ磬Web·þÎñÆ÷¡¢Êý¾Ý¿â·þÎñÆ÷µÈ¡£ÓÈÆäÊÇÔÚÓû§±È½Ï¶à£¬¼ìË÷µÄÊý¾ÝÁ¿±È½Ï´óµÄÇé¿öÏ£¬»á¸ø°üÀ¨Óû§ÔÚÄڵĸ÷¸ö·½ÃæÔì³É²»Ð¡µÄÀ§ÄÑ¡£Èç¹ûÄܹ»½«Êý¾Ý¿ ......