我遇到了從我的SQL數據庫(代碼如下)中讀取圖像數據類型blob的方式問題。當我直接訪問此頁面時,此代碼正常工作。 PDF將打開並工作得很好。但是,當我嘗試使用此頁面下載文件並以編程方式將其保存到文件系統時,它失敗(500服務器錯誤),並且我已驗證它是相同的URL。如何將SQL Server圖像數據類型保存到文件系統?
所以,我的問題是從數據庫映像數據類型下載文件並將其保存到磁盤的最佳方式是什麼?
PDF.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Theme = String.Empty ' disable theme
If (Request.ServerVariables("HTTP_USER_AGENT").IndexOf("MSIE") > 0) Then
Response.Cache.SetCacheability(HttpCacheability.Private)
Else
Response.Cache.SetCacheability(HttpCacheability.NoCache)
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim interns As IEnumerable(Of InternMag.Intern) = InternMag.Intern.GetInternForPhotoOrResume(New Guid(Request.QueryString("studentid")))
For Each intern As InternMag.Intern In interns
Response.ContentType = intern.ResumeFileType
Response.AddHeader("Content-Disposition", "attachment; filename=""Resume" & intern.ResumeFileExtension & """")
Response.BinaryWrite(CType(intern.ResumeFile.ToArray(), Byte()))
Next
End Sub
</script>
你知道我在哪裏能得到這個實現的例子嗎? – EdenMachine 2010-07-12 12:20:18