I need to disable the export excel in report viewer in asp.ne
I have debugged , shows "Object reference not set to an instance of an object" in this line
"Dim ListRenderingExtensions As System.Reflection.MethodInfo = m_previewService.FieldType.GetMethod("ListRenderingExtensions", Flags)"

pls help me

  Protected Sub DisableFormat(ByRef viewer As ReportViewer, ByVal formatName As String)

        Const Flags As System.Reflection.BindingFlags = System.Reflection.BindingFlags.NonPublic + System.Reflection.BindingFlags.Public + System.Reflection.BindingFlags.Instance
        Dim m_previewService As System.Reflection.FieldInfo = viewer.LocalReport.GetType().GetField("m_previewService", Flags)
        Dim ListRenderingExtensions As System.Reflection.MethodInfo = m_previewService.FieldType.GetMethod("ListRenderingExtensions", Flags)
        Dim previewServiceInstance As Object = m_previewService.GetValue(viewer.LocalReport)
        Dim extensions As IList = ListRenderingExtensions.Invoke(previewServiceInstance, Nothing)
        Dim name As System.Reflection.PropertyInfo = extensions(0).GetType().GetProperty("Name", Flags)

        Dim extension As Object

        For Each extension In Extensions
            If (String.Compare(name.GetValue(extension, Nothing).ToString(), formatName, True) = 0) Then
                Dim m_isVisible As System.Reflection.FieldInfo = extension.GetType().GetField("m_isVisible", System.Reflection.BindingFlags.NonPublic + System.Reflection.BindingFlags.Instance)
                m_isVisible.SetValue(extension, True)
                Dim m_isExposedExternally As System.Reflection.FieldInfo = extension.GetType().GetField("m_isExposedExternally", System.Reflection.BindingFlags.NonPublic + System.Reflection.BindingFlags.Instance)
                m_isExposedExternally.SetValue(extension, True)
                Exit For
            End If
        Next extension

    End Sub

    Protected Sub ReportViewer1_PreRender(sender As Object, e As EventArgs) Handles ReportViewer1.PreRender
        Call DisableFormat(Me.ReportViewer1, "Excel") ' Disable EXCEL format
    End Sub
3 Years
Discussion Span
Last Post by SteveDotNet

In line 4, has m_previewService been set to null?
Is viewer null? viewer.LocalReport?
viewer.LocalReport.GetType().GetField("m_previewService", Flags)

Let us not overlook the obvious.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.