扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<asp:SqlDataSource ID="UploadPictureDataSource" runat="server" ConnectionString="..." InsertCommand="INSERT INTO [Pictures] ([Title], [MIMEType], [ImageData]) VALUES (@Title, @MIMEType, @ImageData)"> <InsertParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="MIMEType" Type="String" /> <asp:Parameter Name="ImageData" /> </InsertParameters> </asp:SqlDataSource> |
Protected Sub UploadPictureUI_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles UploadPictureUI.ItemInserting '引用FileUpload控件 Dim UploadedFile As FileUpload = CType(UploadPictureUI.FindControl("UploadedFile"), FileUpload) '确保已经成功上传一个文件 If UploadedFile.PostedFile Is Nothing OrElse String.IsNullOrEmpty(UploadedFile.PostedFile.FileName) OrElse UploadedFile.PostedFile.InputStream Is Nothing Then ...显示错误信息... e.Cancel = True Exit Sub End If '确保我们在处理一个JPG或GIF文件 Dim extension As String = Path.GetExtension(UploadedFile.PostedFile.FileName).ToLower() Dim MIMEType As String = Nothing Select Case extension Case ".gif" MIMEType = "image/gif" Case ".jpg", ".jpeg", ".jpe" MIMEType = "image/jpeg" Case ".png" MIMEType = "image/png" Case Else '无效文件类型上载 ... 显示错误信息... e.Cancel = True Exit Sub End Select "指定MIMEType和ImageData参数的值 e.Values("MIMEType") = MIMEType '把FileUpload的InputStream加载进字节数组中 Dim imageBytes(UploadedFile.PostedFile.InputStream.Length) As Byte UploadedFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length) e.Values("ImageData") = imageBytes End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者