SharePoint 2013 Excel Service 401 Error

Posted on Updated on

Recently when I’m working with SharePoint Excel services i received below error message.

“Before Opening Book ObjectSystem.Net.SystemNetworkCredentialSystem.Net.WebException: The request failed with HTTP status 401: Unauthorized. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at ExcelService.OpenWorkbook(String workbookPath, String uiCultureName, String dataCultureName, Status[]& status)”

to get rid of this error you have to disable “Loopback Check” from front end servers and app servers. you can follow these steps to disable Loopback Check.

Method 1: Specify host names (Preferred method if NTLM authentication is desired)

  1. Click Start, click Run, type regedit, and then click OK.
  2. In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  3. Right-click MSV1_0, point to New, and then click Multi-String Value.
  4. Type BackConnectionHostNames, and then press ENTER.
  5. Right-click BackConnectionHostNames, and then click Modify.
  6. In the Value data box, type the host name or the host names for the sites, and then click OK.
  7. Quit Registry Editor, and then restart the IISAdmin service.

Method 2: Disable the loopback check (less-recommended method)

  1. Click Start, click Run, type regedit, and then click OK.
  2. In Registry Editor, locate and then click the following registry key:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  3. Right-click Lsa, point to New, and then click DWORD Value.
  4. Type DisableLoopbackCheck, and then press ENTER.
  5. Right-click DisableLoopbackCheck, and then click Modify.
  6. In the Value data box, type 1, and then click OK.
  7. Quit Registry Editor, and then restart your computer.


Happy Coding Smile


SharePoint Brunei User Group Monthly Gathering – March 2015

Posted on

I’m really happy to announce that i will be speaking at the SharePoint Brunei User Group in Brunei, March 31 2015. http://www.sharepointbrunei.net/


How to resolve "The type or namespace name ‘SharePoint’ does not exist in the namespace ‘Microsoft’ Error

Posted on Updated on

  • Go to the Solution explorer.
  • Right click on the Solution Explorer and click Properties.
  • Select Application Tab, by default Target Framework will be .Net Framework 3.5 Client Profile change it to .Net Framework 3.5.
  • Once you change the Target Framework “Target Framework Change “wizard will pop up.
  • Click Yes.
  • Go the Build tab and change the Platform Target to x64.
  • Hit F5 now you will be able to debug successfully.

Create a Custom Site Workflow Activity Using C#

Posted on Updated on

First, create a project to hold and test the custom workflow activity.

To create a site workflow custom activity project
  1. Display the New Project dialog box by pointing to New on the File menu, and then click New Project.

  2. Expand the SharePoint node under either Visual C# or Visual Basic, and then click 2010.

  3. In the Templates pane, select Sequential Workflow.

  4. In the Name box, type AnnouncementBackup and then click OK.

    The SharePoint Customization Wizard appears.

  5. In the What is the local site you want to use for debugging? page, click Next to accept the default site.

    This step also sets the trust level for the solution as farm solution, the only available option for workflow projects.

  6. In the Specify the workflow name for debugging page, accept the default name (AnnouncementBackup – Workflow1). Change the workflow template type to Site Workflow and then click Next.

  7. Click Finish to accept the remaining default settings.

Adding a Custom Workflow Activity Class

Next, add a class to the project to contain the code for the custom workflow activity.

To add a custom workflow activity class
  1. Click Add New Item on the Project menu to display the Add New Item dialog box.

  2. In the Installed Templates tree view, click the Code node and then click Class in the list of project item templates. Use the default name Class1.

  3. Replace all of the code in Class1 with the following:

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; namespace AnnouncementBackup { // This custom activity will back up all of the announcements in // the Announcements list on the SharePoint site. public class Class1 : System.Workflow.ComponentModel.Activity { public Class1() { } // Triggers when the activity is executed. protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { try { // Get a reference to the SharePoint site. SPSite site = new SPSite("http://" + System.Environment.MachineName); SPWeb web = site.OpenWeb("/"); // Reference the original Announcements list. SPList aList = web.GetList("/Lists/Announcements"); // If the Announcements Backup list already exists, delete it. try { SPList bList = web.GetList("/Lists/Announcements Backup"); bList.Delete(); } catch { } // Create a new backup Announcements list and reference it. Guid newAnnID = web.Lists.Add("Announcements Backup", "A backup Announcements list.", SPListTemplateType.Announcements); SPList bakList = web.Lists[newAnnID]; // Copy announcements from original to backup Announcements list. foreach (SPListItem item in aList.Items) { SPListItem newAnnItem = bakList.Items.Add(); foreach (SPField field in aList.Fields) { if (!field.ReadOnlyField) newAnnItem[field.Id] = item[field.Id]; } newAnnItem.Update(); } // Put the Backup Announcements list on the QuickLaunch bar. bakList.OnQuickLaunch = true; bakList.Update(); } catch (Exception errx) { System.Diagnostics.Debug.WriteLine("Error: " + errx.ToString()); } return base.Execute(executionContext); } } }

  4. Save the project and then click Build Solution on the Build menu.

  5. Class1 appears as a custom action in the Toolbox under the SharePoint Workflow tab in the Toolbox.

Adding the Custom Activity to the Site Workflow

Next, add an activity to the Workflow to contain the custom code.

To add a custom activity to the site Workflow
  1. Open Workflow1 in the workflow designer in design view.

  2. Click and drag Class1 from the Toolbox and drop it under the onWorkflowActivated1 activity.

  3. Save the project.

Testing the Site Workflow Custom Activity

Next, run the project and start the site workflow. The custom activity creates a backup Announcements list and copies the contents from the current Announcements list into it. The code also checks whether a backup list already exists before creating one. If a backup list already exists, it is deleted. The code also adds a link to the new list on the SharePoint site’s QuickLaunch bar.

To test the site workflow custom activity
  1. Press F5 to run the project and deploy it to SharePoint.

  2. On the QuickLaunch bar, click Lists to display all of the lists available in the SharePoint site. Notice there is only one list for announcements named Announcements.

  3. At the top of the SharePoint Web page, click the Site Actions button and then click Site Workflows.

  4. Under the Start a New Workflow section, click the link for AnnouncementBackup – Workflow1. This starts the site workflow and runs the code in the custom action.

  5. Click the link called Announcements Backup that appears on the QuickLaunch bar. Notice that all of the announcements that are contained in the Announcements list have been copied to this new list.

Original Reference

SharePoint: Create Custom Workflow Activities Using VS 2008 (Video)