I have a custom SharePoint 2010 solution that includes an aspx page. The aspx page in is in the /layouts folder within the solution and I created it by just adding an application page to the solution. I am trying to create a parent-child relationship between two different lists in SharePoint. From the parent I have a custom button on the ribbon that creates a child item with the ID of the parent stamped on it.
The page is just a processing page that forwards on parameters from the parent to the new child item. (i.e. the ID value)
The code generated when I add the aspx page is below:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="processingpage.aspx.cs" Inherits="MY.Solution.Layouts.MY.Solution.processingpage" MasterPageFile="~/_layouts/application.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server"> Processing Page </asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" > Processing Page </asp:Content>
The code behind is as follows:
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Utilities;
using System.Reflection;
namespace MY.Solution.Layouts.MY.Solution
{
public partial class processingpage : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//Get a reference to the SPWeb object
SPWeb oWeb = SPContext.Current.Web;
//Use the Parameters That Are Passed In
SPList thisList = oWeb.Lists[new Guid(Request.QueryString["List"])];
SPListItem thisItem = thisList.GetItemById(int.Parse(Request.QueryString["ID"]));
sContentType = thisItem["ContentType"].ToString();
sContentTypeID = thisItem.ContentTypeId.ToString();
if (sContentType == "Some Content Type")
{
sContentTypeID = "";
sAIID = thisItem["ID"].ToString();
//Redirect to newform.aspx with the Appropriate parameters.
Context.Response.Redirect(oWeb.Url + "/Lists/Blist" + "/NewForm.aspx?AIID=" + sAIAuditID.ToString() + "&ContentTypeId=" + sContentTypeID + "&ParentItemID" + Context.Request["ID"]);
}
else if (sContentType == "Some Content Type")
{
sContentTypeID = "";
sAIID = thisItem["AIID"].ToString();
//Redirect to newform.aspx with the Appropriate parameters.
Context.Response.Redirect(oWeb.Url + "/Lists/AList" + "/NewForm.aspx?AIID=" + sAIID.ToString() + "&ContentTypeId=" + sContentTypeID + "&ParentItemID" + Context.Request["ID"]);
}
else if (sContentType == "Some Content Type")
{
sContentTypeID = "";
sAICID = thisItem["AICID"].ToString();
//Redirect to newform.aspx with the Appropriate parameters.
Context.Response.Redirect(oWeb.Url + "/Lists/CList" + "/NewForm.aspx?AICID=" + sAICID.ToString() + "&ContentTypeId=" + sContentTypeID + "&ParentItemID" + Context.Request["ID"]);
}
else
{
LoggingService.LogError("MY.Solution - Processing Page", "No Applicable Content Type Found.");
}
}
catch (Exception ex)
{
LoggingService.LogError("My.Solution - Processing Page", ex.Message);
}
finally
{
//DO SOME FINAL THINGS HERE WHEN REQUIRED.
}
}
}
}
In the page I need to use Request.QueryString to get the values from the URL. But when I deploy the solution and load the page I get the error:
'MY.Solution.Layouts.MY.Solution.processingpage' is not allowed here because it does not extend class 'System.Web.UI.Page'.
When I change the line:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="processingpage.aspx.cs" Inherits="MY.Solution.Layouts.MY.Solution.processingpage" MasterPageFile="~/_layouts/application.master" %>
to inherit as follows:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="processingpage.aspx.cs" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" MasterPageFile="~/_layouts/application.master" %>
it does not work either.
If I change it to inherit like below:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="processingpage.aspx.cs" Inherits="System.Web.UI.Page" MasterPageFile="~/_layouts/application.master" %>
it also does not work.
Why does the code by Visual Studio for a SharePoint application page not work?

0 commentaires:
Enregistrer un commentaire