locked
Type 'ApiController' is not defined RRS feed

  • Question

  • User-1767698477 posted

    I am trying to test the Syncfusion pdf viewer control which comes with the Essentials Studio JS1. They have some neat tools, but they are a little cumbersome to say the least. Here is the controller.vb below. I need to be able to access session variables inside of this, or pass in the path to a file. I tried to setup the code to pass in a parameter but I could not get it to work. I have been reading around on this and I see a page to modify the global.asax page. I added the AspApplication class below, but I'm not sure if that is right or what else to do after adding this. The path to the .pdf image is passed through a button click on a gridview. 

    Global.asax:

    <%@ Application Language="VB" %> <%@ Import Namespace="System.Web.Routing" %> <%@ Import Namespace="System.Web.Optimization" %> <%@ Import Namespace="System.Web.Http" %> <%@ Import Namespace="Syncfusion.Licensing" %> <script runat="server"> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Syncfusion Licensing Register SyncfusionLicenseProvider.RegisterLicense("MDAxQDMxMzgyZTMxMmUzMG14bzE1b3ZqcTI4cUJyQVlSVXpyYTQwWCtoYzJSNHVLQVcwaStwZ1Bsd2s9") ' Code that runs on application startup AuthConfig.RegisterOpenAuth() RouteConfig.RegisterRoutes(RouteTable.Routes) System.Web.Http.GlobalConfiguration.Configuration.Routes.MapHttpRoute(name:="DefaultApi", routeTemplate:="api/{controller}/{action}/{id}", defaults:=New With {.id = System.Web.Http.RouteParameter.[Optional] }) End Sub Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application shutdown End Sub Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error occurs End Sub Public Class AspApplication Inherits System.Web.HttpApplication Protected Sub Application_PostAuthorizeRequest() If IsWebApiRequest() Then HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required) End If End Sub Private Function IsWebApiRequest() As Boolean Return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative) End Function End Class

    PdfViewerController.vb

    Imports System.IO
    Imports System.Linq
    Imports System.Net
    Imports System.Net.Http
    Imports System.Web
    Imports System.Web.Http
    Public Class PdfViewerController
        Inherits ApiController
        Private viewerHelper As New PdfViewerHelper()
        Public Function Load(jsonResult As Dictionary(Of String, String)) As Object
    
            'load the multiple document from client side 
            If jsonResult.ContainsKey("newFileName") Then
                Dim name = jsonResult("newFileName")
                Dim pdfName = name.ToString()
                viewerHelper.Load(Helper.GetFilePath("" + pdfName))
            Else
                'Initially load the PDF document from the data folder.
                If jsonResult.ContainsKey("isInitialLoading") Then
                    If jsonResult.ContainsKey("file") Then
                        Dim name = jsonResult("file")
                        viewerHelper.Load(name)
                    Else
                        'viewerHelper.Load(Helper.GetFilePath(pathtofile))
                        viewerHelper.Load(Helper.GetFilePath("HTTP Succinctly.pdf"))
                    End If
                End If
            End If
            Dim sdf As String = jsonResult.ToString
            Return JsonConvert.SerializeObject(viewerHelper.ProcessPdf(jsonResult))
        End Function
        Public Function FileUpload(jsonResult As Dictionary(Of String, String)) As Object
            If jsonResult.ContainsKey("uploadedFile") Then
                Dim fileurl = jsonResult("uploadedFile")
                Dim byteArray As Byte() = Convert.FromBase64String(fileurl)
                Dim stream As New MemoryStream(byteArray)
                viewerHelper.Load(stream)
            End If
            Dim output As String = JsonConvert.SerializeObject(viewerHelper.ProcessPdf(jsonResult))
            Return output
        End Function
        Public Function Download(jsonResult As Dictionary(Of String, String)) As Object
            Return (viewerHelper.GetDocumentData(jsonResult))
        End Function
    End Class
    
    	Public Class Helper
    		Public Shared Function GetFilePath(path As String) As String
    			Dim _dataPath As String = GetCommonFolder(New DirectoryInfo(HttpContext.Current.Request.PhysicalApplicationPath))
    			_dataPath += Convert.ToString("\") & path
    			Return _dataPath
    		End Function
    
        Private Shared Function GetCommonFolder(dtInfo As DirectoryInfo) As String
    
            Dim _folderNames = dtInfo.GetDirectories("Data/PdfViewer")
            If _folderNames.Length > 0 Then
                Return _folderNames(0).FullName
            End If
    
            Return If(dtInfo.Parent IsNot Nothing, GetCommonFolder(dtInfo.Parent), String.Empty)
        End Function
    End Class
    

    Thursday, June 4, 2020 12:56 AM

Answers

  • User-1767698477 posted

    Issue is resolved

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 24, 2020 4:50 AM