Showing posts with label custom pages. Show all posts
Showing posts with label custom pages. Show all posts

December 19, 2008

Using SharePoint rich text editor (InputFormTextBox) in your application pages

As the SharePoint rich text editor is located in the Microsoft.SharePoint.WebControls namespace (Microsoft.SharePoint assembly), you have to add the following Register tag on your aspx page.

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
After that, you simply have to add the InputFormTextBoxt control in your page.

<SharePoint:InputFormTextBox Rows="10" MaxLength="1000" id="txtMyRichTextBox" runat="server" RichText="true" RichTextMode="FullHtml" TextMode="MultiLine"  Height="400px" Width="250px"></SharePoint:InputFormTextBox>
The result is the following:



MSDN link: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.inputformtextbox.aspx

December 12, 2008

How to set custom forms (new, edit and display) for a specific content type by code

Let's imagine a content type e.g. Student and you want to set custom forms for it (new, edit and display) as in the previous example. The custom forms have to be set using the NewFormUrl, EditFormUrl and DisplayFormUrl properties of the SPContentType class.

using (SPSite mySiteCollection = new SPSite("http://myserver/myspsite"))
{
    using (SPWeb mySite = mySiteCollection.OpenWeb(mySiteCollection.RootWeb.ID))
    {
        SPList studentsList = mySite.Lists["Students"];
        SPContentType studentContentType = studentsList.ContentTypes["Student"];
        string newurl = "_layouts/STUDENT/APPLICATIONPAGES/NewStudent.aspx";
        string editurl = "_layouts/STUDENT/APPLICATIONPAGES/EditStudent.aspx";
        string displayurl = "_layouts/STUDENT/APPLICATIONPAGES/DisplayStudent.aspx";
        studentContentType.EditFormUrl = editurl;
        studentContentType.NewFormUrl = newurl;
        studentContentType.DisplayFormUrl = displayurl;
        studentContentType.XmlDocuments.Delete("http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url");
        studentContentType.Update();
        studentsList.Update();
    }
}

December 08, 2008

How to set custom forms (new, edit and display) for a specific content type by CAML definition

Let's imagine a content type e.g. Student and you want to set custom forms for it (new, edit and display). The custom forms have to be declared under the XmlDocuments node of the content type CAML definition.

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType
        ID="0x01004037ADCF3A5C4b648FFC4DA96C965CDE"
        Name="Student"
        Description="Create a new student"
        Version="0"
        Group="Custom Content Types" >
    <FieldRefs>
      <!-- add in and rename built-in WSS Title column-->
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Name" Sealed="TRUE"  />
      <!-- custom fields-->
      <FieldRef ID="{756D3B72-AC72-4e0a-8B6D-1E2573251816}" Name="CardNumber" DisplayName="Card Number" />
      <FieldRef ID="{0D6C76FD-A9B6-4613-9429-06385411E9D7}" Name="StudyYear" DisplayName="Study Year" />
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>_layouts/STUDENT/APPLICATIONPAGES/NewStudent.aspx</New>
          <Edit>_layouts/STUDENT/APPLICATIONPAGES/EditStudent.aspx</Edit>
          <Display>_layouts/STUDENT/APPLICATIONPAGES/DisplayStudent.aspx</Display>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>

July 14, 2008

Styles not rendered when using the SharePoint DateTimeControl in custom pages

When using the SharePoint DateTimeControl in custom pages, the popup calendar is rendered without styles. I don't know why but the problem is that the datepicker.css stylesheet is not referenced as explained on the Rich Finn's blog (http://blog.richfinn.net/2006/12/10/SharePointDateTimeControlDoesNotRenderStyles.aspx).

Have a look on the iframe.aspx page located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.DatePickerFrame"      %> 
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% SPSite spServer = SPControl.GetContextSite(Context); SPWeb spWeb = SPControl.GetContextWeb(Context); %>
<html dir="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_dir_value%>' EncodeMethod='HtmlEncode'/>">
    <HEAD>
    <META Name="GENERATOR" Content="Microsoft SharePoint">
    <SharePoint:CssLink runat="server"/>
    <script src="./DatePicker.js"></script>
    <title>Date Picker</title>
    </HEAD>
    <BODY onload="PositionFrame('DatePickerDiv');" onkeydown="OnKeyDown(this);" style="margin:0;">
      <SharePoint:SPDatePickerControl id="DatePickerWebCustomControl" runat="server" >
          </SharePoint:SPDatePickerControl>
    </BODY>
</HTML>

To solve the problem, you have to add manually the reference to the stylesheet.

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.DatePickerFrame"      %> 
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Import Namespace="Microsoft.SharePoint" %> 
<% SPSite spServer = SPControl.GetContextSite(Context); SPWeb spWeb = SPControl.GetContextWeb(Context); %>
<html dir="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_dir_value%>' EncodeMethod='HtmlEncode'/>">
    <HEAD>
    <META Name="GENERATOR" Content="Microsoft SharePoint">
    <link rel="stylesheet" type="text/css"href="/_layouts/1033/styles/datepicker.css"/>
    <SharePoint:CssLink runat="server"/>
    <script src="./DatePicker.js"></script>
    <title>Date Picker</title>
    </HEAD>
    <BODY onload="PositionFrame('DatePickerDiv');" onkeydown="OnKeyDown(this);" style="margin:0;">
      <SharePoint:SPDatePickerControl id="DatePickerWebCustomControl" runat="server" >
          </SharePoint:SPDatePickerControl>
    </BODY>
</HTML>