簡體   English   中英

將BinaryWrite保存到服務器路徑

[英]Save BinaryWrite to Server Path

我正在將文件保存到遠程托管服務器上的SQL Server。 我可以上傳它們。 但是我需要將文件下載到遠程服務器路徑。 下面的代碼提取文件,但將其保存到客戶端。

我嘗試將Response.BinaryWrite(bytes)替換為Response.TransmitFile(Server.MapPath(“〜/ App_Data / DS / sailbig.jpg”),但找不到錯誤文件。

我只想提取存儲在sql中的文件並將其放在服務器上的目錄中,以便以后可以在代碼中使用它,但我無法弄清楚。 感謝您的幫助,這對我來說是一種愛好。

    Dim filePath As String = HttpContext.Current.Server.MapPath("~/App_Data/DS/")
    Dim bytes() As Byte = CType(dt.Rows(0)("Data"), Byte())
    response.Buffer = True
    response.Charset = ""
    response.Cache.SetCacheability(HttpCacheability.NoCache)
    response.ContentType = dt.Rows(0)("ContentType").ToString()
    Response.AddHeader("content-disposition", "attachment;filename=" & dt.Rows(0)("FileName").ToString())
    Response.BinaryWrite(bytes)
    Response.Flush()
    Response.End()

使用File.WriteAllBytes

Dim filePath As String = HttpContext.Current.Server.MapPath("~/App_Data/DS/")
Dim bytes() As Byte = CType(dt.Rows(0)("Data"), Byte())

File.WriteAllBytes(filePath & dt.Rows(0)("FileName").ToString(), bytes)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM