Why can't I run ASP in SharePoint 2007?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NEOXO
    New Member
    • Sep 2011
    • 1

    Why can't I run ASP in SharePoint 2007?

    I have an ASP page that generates XML after querying an MS Access Datbase. But when I upload it to a SharePoint 2007 server, I am not allowed to upload .asp files. So I named it .aspx and uploaded it successfully. When hitting the .aspx page I just uploaded, I get an ERROR page:

    Error

    An error occurred during the processing of /sites/mysite/portal/xmlgetdata.aspx . Code blocks are not allowed in this file.

    Troubleshoot issues with Windows SharePoint Services.

    What can I do to make it work? Will I have to convert my classic ASP code to ASP .NET code? If so, can someone help me convert my ASP code to ASP .NET?

    Here's the ASP code for xmlgetdata.asp:
    Code:
    <% @ Language="VBScript" %>
    <%
      ' Declare all variables.
      Option Explicit
      Dim objCN,objRS,objField
      Dim strSQL,strCN
      Dim strName,strValue
    
      ' Buffer and output as XML.
      Response.Buffer = True
      Response.ContentType = "text/xml"
    
      ' Start our XML document.
      Response.Write "<?xml version=""1.0""?>" & vbCrLf
      Response.Write "<?xml:stylesheet type=""text/xsl"" href=""xmlrender.xsl""?>" & vbCrLf
    
      ' Set SQL and database connection string.
      strSQL = "SELECT * FROM SubNav"  
      strCN = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=\\server01\mydb1.mdb"
    
      ' Open the database connection and recordset.
      Set objCN = Server.CreateObject("ADODB.Connection")
      objCN.Open strCN  
      Set objRS = objCN.Execute(strSQL)
    
      ' Output start of data.
      Response.Write "<DATABASE>" & vbCrLf
    
      ' Loop through the data records.
      While Not objRS.EOF
        ' Output start of record.
        Response.Write "<RECORD>" & vbCrLf
        ' Loop through the fields in each record.
        For Each objField in objRS.Fields
          strName  = objField.Name
          strValue = objField.Value
          If Len(strName)  > 0 Then strName = Server.HTMLEncode(strName)
          If Len(strValue) > 0 Then strValue = Server.HTMLEncode(strValue)
          Response.Write "<FIELD>" & vbCrLf
          Response.Write "<NAME>" & strName & "</NAME>" & vbCrLf
          Response.Write "<VALUE>" & strValue & "</VALUE>" & vbCrLf
          Response.Write "</FIELD>" & vbCrLf
        Next
        ' Move to next record in database.
        objRS.MoveNext
        ' Output end of record.
        Response.Write "</RECORD>" & vbCrLf
      Wend
    
      ' Output end of data.
      Response.Write "</DATABASE>" & vbCrLf
    %>
    Thank you in advance for your help guys!!
    Last edited by Frinavale; Sep 23 '11, 02:16 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You have to talk to your Sharepoint administrator about adding any pages that have code. It's restricted for security.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I could understand why an administrator wouldn't want ASP pages on their server.

      I recommend downloading Visual Studio Express and creating a proper ASP.NET (aspx) page.

      You would have to move the code you have posted here into a method that handles the Page Load Event.

      You're going to have to make some modifications to use .NET controls instead of the vb code that you're using.

      -Frinny

      Comment

      Working...