Saturday, January 18, 2014

SharePoint Web Parts Maintenance Page

SharePoint web part maintenance pages allows to manage (reset, delete) the web parts embedded into a particular page. It's useful in situations where its required to remove any web parts from a page which has caused a page crash.

For an instance if the page urls is:
http://localhost:1000/SitePages/Home.aspx

you can get the maintenance page by typing in "?contents=1" at the end of the URL string. Below is a sample:

http://localhost:1000/SitePages/Home.aspx?contents=1

This works the same in  SharePoint 2007, 2010 and 2013

Saturday, November 23, 2013

SharePoint Debug - Attach to Worker Process

Each SharePoint web application is run under a dedicated worker processes. Specially when it comes to DEV environments, when debugging a solution it's best to attach the code only to the target worker process. This avoids the hassle among the DEV team :) . It's pretty simple  to find the worker process related to the target web application. Follow these simple steps.


1) Start Command prompt with Administrator privileges
2) Navigate to C:\Windows\System32\inetsrv directory
3) Type in appcmd list wp


You get the list of  worker processes along with the web application which is running on it. Now in the Visual Studio IDE go to debugger and attach your code by selecting the appropriate worker process. Under the set of w3wp exe's you can pinpoint the exact one.


Saturday, October 26, 2013

Get-SPWebApplication is not recognised as the name of the cmdlet

When you try to execute SharePoint specific commands through PowerShell, might come across a message

"Get-SPWebApplication is not recognized as the name of the cmdlet ......"

The SP specific commands are not being recognized in PowerShell at this point. Adding a snap in would do the trick. Type the below command in your PowerShell  window.

Add-PSSnapin Microsoft.Sharepoint.Powershell

That's it. Provided that the rights in DB are there, you should be able to execute SharePoint based commands now.

Wednesday, September 25, 2013

When creating a Folder in Library - The server was unable to save the form at this time. Please try again [SP 2013]

In SharePoint server 2013 I tried to create a folder in side a document library and got this message.
"The server was unable to save the form at this time. Please try again".



 Was quite surprised at the beginning, but I kept getting this message over and over again. It seems like this is happening cause of a memory issue. At the time, the machine had only 8GB of RAM, which really should reach up to 16 GB of RAM for better performance.

Certain workarounds suggested that you restart the "SharePointSearch Host Controller Service" as a temporary solution to  free up some memory space. But it didn't do any good in my case.

Some were pointing out that the issue may have happened due to any add-on's installed in IE, But I didn't have any special add-on's in IE. Tried out the same using Chrome just to make sure I'm not missing anything. But still had no luck.

As a last resort did the famous iisreset assuming that anything held up will be released or refreshed. Nope, that didn't work either.

After some digging, I realized that Anonymous access to the site was disabled in IIS. Tried enabling it which was then followed by an iisreset and  ... Voila !! ... The Folder gets created !!   :)


So you have to Enable anonymous access at site level in IIS just to add folders to document libraries in SP2013 ??


....This somehow smells to me like a tiny 




Sunday, June 30, 2013

Connecting Server to an existing SharePoint Farm

Once, I had two separate SharePoint 2007 farms having its own server. I needed to change that to one farm with two servers. So I had to remove one farm from one server machine and connect it as a WFE to the existing farm in the other server. The first step was to remove one SharePoint farm.

1) You can use the following command to disconnect the database from SharePoint:

PSCONFIG.EXE -cmd configDB -disconnect








2) Then remove the SharePoint related DB's from SQL Server



3) Run the SharePoint configuration wizard. You get a message as below. Select "Yes".



4) In the configuration wizard, choose connect to existing server farm.



5) Select the database of the server which you need to connect and specify the DB access account to be used. Let the configuration happen.


Now go to the Central Admin. Select Operations. Select Servers in Farm. The new addition to the farm will be listed down.


Thursday, May 16, 2013

Creating a simple Event Receiver in SharePoint 2013

Create an empty SharePoint 2013 project in Visual Studio 2012. In the project, select add new item and select Event Receiver


Select the type of event receiver you need to add, and select the events you need to handle.



In this sample I'm trying to update a SharePoint list based on file changes happening to a separate SharePoint library. Basically, the list will act like a log. So we need to create the library and a list. Here, I have created the Department library to add and maintain documents and also created DocumentLog list to log the changes happening to the library. 

In the list I have three columns, Title, Action & DateAndTime in order to catalog the changes happening to the library.


[The created document library and list]

Back to the SharePoint project. Now go to the event receiver .cs file and you'll get a bunch of methods base on your selection during event receiver creation. Edit the code as below to implement the logic. Note that the ItemAdded method is used instead of the ItemAdding method.


public override void ItemAdded(SPItemEventProperties properties)
        {
            //base.ItemAdded(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Added";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

public override void ItemUpdating(SPItemEventProperties properties)
        {
            //base.ItemUpdating(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Updated";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

public override void ItemDeleting(SPItemEventProperties properties)
        {
            //base.ItemDeleting(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Deleted";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }


As I am targeting to add the event receiver only to the Department document library, the Elements.xml file requires a change.



 Note that I have commented out the setting which points to all document libraries, instead pointed to Department document library. The edited Elements.xml file is as below:


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!--   <Receivers ListTemplateId="101"> -->
  <Receivers ListUrl="Department">

   <Receiver>
        <Name>DepartmentEventReceiverItemAdded</Name>
        <Type>ItemAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>MySharePointProject.ListEventReceiver.DepartmentEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>

      <Receiver>
        <Name>ListEventReceiverItemUpdating</Name>
        <Type>ItemUpdating</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>MySharePointProject.ListEventReceiver.DepartmentEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
      <Receiver>
        <Name>ListEventReceiverItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>MySharePointProject.ListEventReceiver.DepartmentEventReceiver</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
</Receivers>
</Elements>

Compile and deploy the solution to your site. Now you may play around with the library and observe the changes happening to the list.... :)

I have added a document, uploaded, added, modified the 3 docs and then deleted one of the docs respectively.


And here's what I get in the DocumentLog list.


Monday, May 6, 2013

Installing SharePoint 2007

Back in the day SharePoint 2007 was a hot topic for SharePoint newbies. Seems SP 2007 is still around in use and thought of blogging on key points to note on the installation and configuration.

Installation

Choose the installation type you want. Here I choose Advanced.



Choose the installation server type. I have selected "Complete"

Once the installation is done you will be prompted. Then MOSS will fire up the "SharePoint Products and Technologies Configuration Wizard"

1) System prompts the services that would be restarted before starting the wizard.

2) Server farm option: Creating New vs. Connecting to existing. I'm creating new


3) Specify database settings

4) Specify Central Admin Web App settings

5) Before the wizard starts, the user specified details are displayed

6) Then the wizard runs

7) Once the configuration wizard completes user is prompted of the end result.

8) Then, user is directed to the Central Admin. The "Services on Server" section indicates that services have to be configured



9) Note that you have to start the below services started in the image. Service settings are pretty straight forward.


Creating a new Shared Service Provider

1) Navigate to "Application Management" to create a new SSP. Select the link as shown below:

2) Select "New SSP"

3) In the "New Shared Service Provider" page, specify the web application for SSP and MySite

I have not created any web application yet. Hence I am creating two now. Select the links on the page in order to create new web applications. You will be directed to "Create New Web Application" page. Once it's done system directs you back to the Create SSP page.

3.1) Creating a web application

A web application can be easily created using the following steps. Specify the IIS website and port to be used for the new web application.


Provide the application pool name and the security account to be used.


Provide the database server name, database name & the authentication


Once the two applications are created the SSP can be created. 

4) On completing SSP creation you get a success message


Now in the Shared Services Administration page the SSP is displayed.