09
Jul
10

Migrate invokereport.php to vb.net for MapGuide 2011

I had to move the invokereport.php that I always use for passing the key values from MapGuide to a pre-existing report (such as one written in PHP, CFM,ASPX, ASP, CGI, etc)

The report expects a few things from MapGuide, and you will have to set them up in MapGuide Studio:

<%@ Page Language="VB" debug=true %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="OSGeo.MapGuide" %>
<%
    ' get the SESSION id
    Dim configFilePath As String = "C:/Program Files/Autodesk/MapGuideEnterprise2011/WebServerExtensions/www/webconfig.ini"
    Dim errorMsg As String
    Dim mgSessionId As String = Request("SESSION")
    Dim mapName As String = Server.UrlDecode(Request("MAPNAME"))
    Dim layerName As String = Request("LAYER")
    Dim reportUrl As String = Request("URL")
    Dim methodType As String = Request("METHOD")
    Dim keyName As String = Request("KEY")
    Dim objkeys As String = "'0'"
        
    
    Try

        MapGuideApi.MgInitializeWebTier(configFilePath)
        Dim userInfo As MgUserInformation = New MgUserInformation(mgSessionId)
        Dim siteConnection As MgSiteConnection = New MgSiteConnection()
        siteConnection.Open(userInfo)
        Dim resourceService As MgResourceService = siteConnection.CreateService(MgServiceType.ResourceService)
        Dim featureService As MgFeatureService = siteConnection.CreateService(MgServiceType.FeatureService)
        Dim queryOptions As MgFeatureQueryOptions = New MgFeatureQueryOptions()
        Dim map As MgMap = New MgMap(siteConnection)
        map.Open(mapName)
        Dim sel As MgSelection = New MgSelection(map)
        sel.Open(resourceService, mapName)
        Dim selLayers As MgReadOnlyLayerCollection = sel.GetLayers()
        Dim layerCount As Integer = selLayers.GetCount()
        
       
        Dim i As Integer = 0
        Dim layer As MgLayerBase
        'Loop through layers
        If (layerCount > 0) Then
            For i = 0 To layerCount - 1
                layer = selLayers.GetItem(i)
                Dim featureClassName As String = layer.GetFeatureClassName()
               
                
                Dim featureReader As MgFeatureReader = sel.GetSelectedFeatures(layer, featureClassName, True)
               
                If (layer.GetName() = layerName) Then
                    While (featureReader.ReadNext())
                        If (objkeys.Length <> 0) Then
                            objkeys = objkeys + ","
                        End If
                        objkeys = objkeys + "'" + featureReader.GetString(keyName) + "'"

                    End While
                    featureReader.Close()
                End If

            Next i
           
        End If
    Catch mge As MgException
        errorMsg = mge.GetExceptionMessage() + "<br><br>" + mge.GetDetails()
        Response.Write(errorMsg)
    Catch e As Exception
        errorMsg = e.Message()

    End Try
    
   

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body onload="OnPageLoad()">
    <form action="<%=reportUrl %>"  method="<%=methodType%>" name="invokeReport" target="_self">
    <input name="OBJ_KEYS" type="hidden"  value="<%=objkeys%>"/>
    
    
    </form>
    
<script language="JavaScript" type="text/javascript">
function OnPageLoad()
{
 document.invokeReport.submit();
 
 
}
</script>
    
    
</body>
</html>

 
Advertisements

12 Responses to “Migrate invokereport.php to vb.net for MapGuide 2011”


  1. 1 Alejandro
    July 28, 2010 at 2:59 pm

    Hi!
    Nice blog!
    Do you know any trouble with MapGuide 2009 on Windows 2003 and Oracle 10g…?
    can I contact (email) with you?

    best regards!
    alex

  2. August 9, 2010 at 7:01 pm

    Hi Alex, no this works great. Oracle client (Admistrator) is recommended.

  3. December 4, 2012 at 7:33 pm

    Gordon

    Thanks for the vb.net script for the report that did the trick!

    Mitch

  4. April 29, 2013 at 7:05 pm

    Gordon,

    Thanks for the vb.net script works well. Hid the invokereport.aspx in the scriptFrame and executes an .asp page in another frame at the bottom. Works and feels just like mapguide 6.5.

    I’ve been trying to adapt your script for the myonselectionchanged.htm to fire the invokereport.asp automatically to no avail. I can get it to fire and load my asp report page but the key from the parcel layer isn’t right. the key it’s putting into my url string is something it’s grabbing from the map that i haven’t figured out yet.

    Found this site by chance, but my web host J. Davenport dropped your name as well.

    Keep up the good work.

  5. 5 Wayne
    May 22, 2014 at 3:14 pm

    hello Gordon,
    I am have some prob’s with this code and I am unsure why. I did cut and paste the code 100% and setup the url in studio 100%. and I am getting this.

    Server Error in ‘/mapserver2014’ Application.

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30451: Name ‘MapGuideApi’ is not declared.

    Source Error:

    Line 22: Try
    Line 23:
    Line 24: MapGuideApi.MgInitializeWebTier(configFilePath)
    Line 25: Dim userInfo As MgUserInformation = New MgUserInformation(mgSessionId)
    Line 26: Dim siteConnection As MgSiteConnection = New MgSiteConnection()

    any help would be greatly appreciated

  6. May 22, 2014 at 3:47 pm

    Make sure this line is correct for 2014:
    “C:/Program Files/Autodesk/MapGuideEnterprise2011/WebServerExtensions/www/webconfig.ini”

    “C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension 2014\www\webconfig.ini”

  7. 7 Wayne
    May 22, 2014 at 5:57 pm

    I did I also found out by messing around that I needed to copy my aspx file to C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension 2014\www\mapviewernet
    for it to not error. but now I get this
    Problem:\nThe application encountered a problem and could not finish the operation you just requested properly.\n\nSolution:\nIf it\’s the first time you met this problem, try again or restart the application / session; otherwise, describe the steps to reproduce this problem to the server administrator for suggestions.

  8. 8 Wayne
    May 22, 2014 at 6:04 pm

    also if I open my aspx file in that dir I get this below… just to get the ajax viewer to work I had to make a app pool just for the ajax using .net 4 and not 2

    Server Error in ‘/mapviewernet’ Application.
    ——————————————————————————–

    Could not load file or assembly ‘MapGuideDotNetApi’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.BadImageFormatException: Could not load file or assembly ‘MapGuideDotNetApi’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

  9. 9 wayne
    June 6, 2014 at 6:03 pm

    using vb.net is there a way to get the current layer name selected and not have it hard coded??? I want to maybe like a control page to say if it is this layer use this key type of thing

  10. June 6, 2014 at 6:19 pm

    At the line: If (layer.GetName() = layerName) Then

    you can use anything you wish. You have the layer name of the selected with layer.GetName() so you can do what you want there…

  11. 11 wayne
    June 6, 2014 at 8:05 pm

    thanks I will give that a shot .. I am unsure of all the different command etc that work with aims 2014 or any aims really…
    thhx so much for all your tips and help !!!!!
    so far I know this don’t work
    If (layer.GetName() = “Primary Parcel City”) Then
    Dim keyName As String = (“PARCEL_LINK”)

    While (featureReader.ReadNext())
    If (objkeys.Length 0) Then
    objkeys = objkeys + “,”
    End If
    objkeys = objkeys + “‘” + featureReader.GetString(keyName) + “‘”

    End While
    featureReader.Close()
    End If

  12. 12 wayne
    June 9, 2014 at 1:37 pm

    Gordon I got it!!!! was my error Primary Parcel City should have been Parcels Primary City… to much in my mind I guess thx !!!!!!! your examples are great!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Gordon Luckett

Arrow Geomatics Inc's Gordon Luckett

Contact

gordon dot luckett at arrowgeo dot com 1-519-837-9500 (Arrow Geomatics Inc.)

Checkout MapGuide Guy’s Youtube Channel

gordonluckett@twitter


%d bloggers like this: