Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 20764

How to download a file pdf or image in Reporting Services?

$
0
0

There is a kind of scenario that users want to download the receptive brochures or training document which is stored in server as  C:/SolutionName/File  . I need to download the file .

But if i use ="javascript:void(window.open('" & "file://C:/XYZABC_Attachments/XYZABC.xlsx" & "','_blank'))" . It gives an error 

VM8623:1 Not allowed to load local resource: file:///D:/XYZABC_Attachments/XYZABC.xlsx 

But i can download the file , by hitting the URL in the  browser directly : file:///D:/XYZABC_Attachments/XYZABC.xlsx 

I have also tried using Code but it dosent help , due to issue in HTTPResponse .

Following is the code i have used for Code in Report properties:

Function DownloadFile(ByVal fname As String, ByVal forceDownload As Boolean)

        Dim Request As System.Web.HttpRequest 

Dim path As String = fname
    Dim name As String = System.IO.Path.GetFileName(path)
    Dim ext As String = System.IO.Path.GetExtension(path)
    Dim type As String = ""

    If ext IsNot Nothing Then

        Select Case ext.ToLower()
            Case ".htm", ".html"
                type = "text/HTML"
            Case ".txt"
                type = "text/plain"
            Case ".docx"
                type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            Case ".doc"
                type = "Application/msword"
            Case ".rtf"
                type = "application/rtf"
            Case ".png"
                type = "image/png"
            Case ".jpg", ".jpeg"
                type = "image/png"
            Case ".bmp"
                type = "image/bmp"
            Case ".gif"
                type = "image/gif"
            Case ".tif", ".tiff"
                type = "image/tiff"
            Case ".pdf"
                type = "application/pdf"
            Case ".ppt"
                type = "application/mspowerpoint"
            Case ".msg"
                type = "application/msoutlook"
            Case ".xml", ".sdxl"
                type = "application/xml"
            Case Else
                type = "application/octet-stream"
        End Select
    End If

    If forceDownload Then
        response.AppendHeader("content-disposition", "attachment; filename=" & name)
    End If

    If type <> "" Then response.ContentType = type
    response.WriteFile(path)
    response.[End]()
End Function

I have been searching options for this from quite a while . 


Viewing all articles
Browse latest Browse all 20764

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>