扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:BLOG 2007年11月6日
关键字: Windows
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 void btnSubmit_Click(object sender, System.EventArgs e) { string strDocExt; //strDocType用于保存上传文件的类型 string strDocType; //用于保存文件大小 int intDocLen; //Stream用于读取上传数据 Stream objStream; SqlConnection BooksConn; SqlCommand cmdUploadDoc; if(IsValid) { if(txtFileContents.PostedFile != null) { //文件类型 strDocExt = CString.Right(txtFileContents.PostedFile.FileName,4).ToLower(); switch(strDocExt) { case ".doc": strDocType = "doc"; break; case ".ppt": strDocType = "ppt"; break; case ".htm": strDocType = "htm"; break; case ".html": strDocType = "htm"; break; case ".jpg": strDocType = "jpg"; break; case ".gif": strDocType = "gif"; break; default: strDocType = "txt"; break; } //上传文件具体内容 intDocLen = txtFileContents.PostedFile.ContentLength; byte[] Docbuffer = new byte[intDocLen]; objStream = txtFileContents.PostedFile.InputStream; //文件保存到缓存 //缓存将保存到数据库 objStream.Read(Docbuffer ,0,intDocLen); BooksConn = new SqlConnection("Server=Server;UID=sa;Database=Books"); 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; BooksConn.Open(); cmdUploadDoc.ExecuteNonQuery(); BooksConn.Close(); } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者