Monthly Archives: October 2013

Create Blog to an Existing Site (without creating new sub site) in SharePoint 2013

Normally, when you would like to have a blog, you will need to create another sub site or site collection.
I found nice trick from Steve Mann blog to create blog to your existing site.

 

It’s very straight forward by executing below powershell in SharePoint 2013 Management Console:

Enable-SPFeature -identity "BlogContent" -url <http://site url>

 

Once you’ve run the command, you will have “Post” included in your SharePoint 2013 Apps list.

blogPost blogPost2

References

http://stevemannspath.blogspot.in/2013/10/sharepoint-2013-adding-blog-to-existing.html

Disable event firing in SharePoint Event Receiver

If you want to update the current item metadata or other item metadata in other list or library and also does NOT need to fire another event for the other item you’ve updated.

In this article, I would like to show you the best way to do it.

///
/// Disabled item events scope
/// 
class DisabledItemEventsScope : SPItemEventReceiver, IDisposable
{
   bool oldValue;
   public DisabledItemEventsScope()
   {
      this.oldValue = base.EventFiringEnabled;
      base.EventFiringEnabled = false;
   }
   public void Dispose()
   {
      base.EventFiringEnabled = oldValue;
   }
}

and in your event receiver method ItemAdded, ItemUpdated, or others

public override void ItemUpdated(SPItemEventProperties properties)
{
   base.ItemUpdated(properties);
   SPListItem currItem = properties.ListItem;
   using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
   {
      currItem["Column2"] = "updated";
      currItem.Update();
   }
}

SharePoint Workflow History – Event Type

As you’ve probably know Workflow History list is hidden, but you could access it through URL:

http://<site collection>/<web>/lists/Workflow History

I found very good reference to decode the Event Type Id from spjeff blog site

EventType ID Member name Description
0 None There is no specific event type for this workflow event.
1 WorkflowStarted The workflow event concerns the workflow instance being initiated.
2 WorkflowCompleted The workflow event concerns the workflow instance being completed.
3 WorkflowCancelled The workflow event concerns the workflow instance being cancelled.
4 WorkflowDeleted The workflow event concerns the workflow instance being deleted.
5 TaskCreated The workflow event concerns a workflow task being created.
6 TaskCompleted The workflow event concerns a workflow task being marked as complete.
7 TaskModified The workflow event concerns a workflow task being modified.
8 TaskRolledBack The workflow event concerns changes to a workflow task being rolled back.
9 TaskDeleted The workflow event concerns a workflow task being deleted.
10 WorkflowError The workflow event concerns the workflow instance generating an error.
11 WorkflowComment The workflow event concerns a comment being written for the workflow instance.

References

  1. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowhistoryeventtype.aspx
  2. https://www.spjeff.com/2010/01/29/workflow-history-event-type-numbers-decoded-2/

Create List Custom Form in SharePoint 2013

Recently, I need to create custom List NewForm.aspx in SharePoint 2013 and intended to include my custom java script inside the aspx page. I tried to implemented it like I used to do or everyone experienced before 2013 as in this article.

When I did that, WebParts and WebPart elements not recognized and my content editor webpart thats included my java script not inserted into my list custom form.

After spending sometime figuring it out, I would like to share my experience here and for my reference as well.

  1. Create new Empty SharePoint project as farm solution and Provide “MyListCustomForm” as Solution name.
  2. Right click SharePoint project > Add New Item > List > Provide List Name “MyList” and click Add.
  3. Right click new List > Add New Item (Text File) > Provide File Name “CustomNewForm.aspx” and click Add.
  4. Set CustomNewForm.aspx Deployment Type as “Element File”. The solution explorer will look like below now.
    MyListCustomForm1
  5. Go to 15 hive folder and search for default NewForm.aspx page that you can copy contents to CustomNewForm.aspx page.
    <%@ Page language="C#" MasterPageFile="~masterurl/default.master"    Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"  %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
    
        <SharePoint:ListProperty ID="ListProperty1" Property="Title" runat="server"/> - <SharePoint:EncodedLiteral ID="EncodedLiteral1" runat="server" text="<%$Resources:wss,listformtitle_newitem%>" EncodeMethod='HtmlEncode'/>
    
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
        <span class="die">
    		<SharePoint:ListProperty Property="LinkTitle" runat="server" id="ID_LinkTitle"/>
    	</span>
    </asp:Content>
    
    <asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageImage" runat="server">
        <img src="/_layouts/15/images/blank.gif?rev=23" width='1' height='1' alt="" />
    </asp:Content>
    
    <asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <SharePoint:UIVersionedContent ID="UIVersionedContent1" UIVersion="4" runat="server">
        <ContentTemplate>
        <div style="padding-left:5px">
        </ContentTemplate>
    </SharePoint:UIVersionedContent>
        <table class="ms-core-tableNoSpace" id="onetIDListForm">
         <tr>
          <td>
         <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main" />
          </td>
         </tr>
        </table>
    <SharePoint:UIVersionedContent ID="UIVersionedContent2" UIVersion="4" runat="server">
        <ContentTemplate>
        </div>
        </ContentTemplate>
    </SharePoint:UIVersionedContent>
    </asp:Content>
    
    <asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
        <SharePoint:DelegateControl ID="DelegateControl1" runat="server" ControlId="FormCustomRedirectControl" AllowMultipleControls="true"/>
        <SharePoint:UIVersionedContent ID="UIVersionedContent3" UIVersion="4" runat="server"><ContentTemplate>
            <SharePoint:CssRegistration Name="forms.css" runat="server"/>
        </ContentTemplate></SharePoint:UIVersionedContent>
        <script>
            alert("My custom javascript added !");
        </script>
    </asp:Content>
    
    <asp:Content ID="Content6" ContentPlaceHolderId="PlaceHolderTitleLeftBorder" runat="server">
    <table cellpadding="0" height="100%" width="100%" cellspacing="0">
     <tr><td class="ms-areaseparatorleft"><img src="/_layouts/15/images/blank.gif?rev=23" width='1' height='1' alt="" /></td></tr>
    </table>
    </asp:Content>
    
    <asp:Content ID="Content7" ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">
    <script type="text/javascript" id="onetidPageTitleAreaFrameScript">
        if (document.getElementById("onetidPageTitleAreaFrame") != null) {
            document.getElementById("onetidPageTitleAreaFrame").className = "ms-areaseparator";
        }
    </script>
    </asp:Content>
    
    <asp:Content ID="Content8" ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server">
    <SharePoint:StyleBlock ID="StyleBlock1" runat="server">
    .ms-bodyareaframe {
        padding: 8px;
        border: none;
    }
    </SharePoint:StyleBlock>
    </asp:Content>
    
    <asp:Content ID="Content9" ContentPlaceHolderId="PlaceHolderBodyLeftBorder" runat="server">
    <div class='ms-areaseparatorleft'><img src="/_layouts/15/images/blank.gif?rev=23" width='8' height='100%' alt="" /></div>
    </asp:Content>
    
    <asp:Content ID="Content10" ContentPlaceHolderId="PlaceHolderTitleRightMargin" runat="server">
    <div class='ms-areaseparatorright'><img src="/_layouts/15/images/blank.gif?rev=23" width='8' height='100%' alt="" /></div>
    </asp:Content>
    
    <asp:Content ID="Content11" ContentPlaceHolderId="PlaceHolderBodyRightMargin" runat="server">
    <div class='ms-areaseparatorright'><img src="/_layouts/15/images/blank.gif?rev=23" width='8' height='100%' alt="" /></div>
    </asp:Content>
    
    <asp:Content ID="Content12" ContentPlaceHolderId="PlaceHolderTitleAreaSeparator" runat="server"/>
    
  6. In MyList Schema.xml, update the Form element for New Form. When UseLegacyForm attribute set to “FALSE”, a default list web part to a custom new form page inside web part zone “Main”.
    <Form Type="NewForm" Url="CustomNewForm.aspx" Path="CustomNewForm.aspx" WebPartZoneID="Main" UseLegacyForm="FALSE"  />
    
  7. Build and Deploy.

MyListCustomForm2

Furthermore, I also find you could have Page_Load event in the custom new form aspx page as per ikarstein