June 13, 2013

Datasheet view error 0x80070057

Problem:
This error occurs when you try to ​edit People OR Group field in datasheet view.
Root cause:
Due to inappropriate declaration of site column \ column in list definition this error occurs
Solution:
   1:  $field = $newSite.RootWeb.Lists["ListName"].Fields.GetFieldByInternalName("FieldName")
   2:  $field.SchemaXml = $field.SchemaXml.Replace("<Field", "<Field List=""UserInfo"" ")
   3:  $field.Update()

If you have any questions you can reach out our SharePoint Consulting team here.

Problem with ItemUpdated Event Reciever and Rename Document

While performing any actions in itemUpdated() event reciever, care should be taken how SPListitem is accessed.
Changed item is generally accessed as follows:
SPListItem item = web.GetListItem(properties.ListItem.Url);
It will work fine as long as any modification to document name is not made. But when a document is renamed, accessing listitem as above will throw an Exception of Nativestack.
Reason: ItemUpdated() is asynchronous event. Hence, it is not necessary when code executes, new URl is available.
Instead, access the changes Listitem as follows,
properties.Web.Lists[].GetItemById(properties.ListItemId);

If you have any questions you can reach out our SharePoint Consulting team here.

Dlls not deployed to GAC - SharePoint 2013, Visual Studio 2012, .Net FW 4.5

​When you create a SharePoint 2013 project in Visual Studio 2012 and I want to deploy it, it deploys fine, but DLL is not in the Global Assembly Cache.
We check for assembly in c:\windows\assembly but it does not appear there. Don't panic!!!
Assembly folder for .NET 4.0 and up have changed to c:\windows\microsoft.net\assembly
If you have any questions you can reach out our SharePoint Consulting team here.

Sign in as Different User in SharePoint 2013

It’s been noted that the “Sign in as a Different User” menu command is missing in SharePoint 2013

You can add the menu item back in, but I would suggest only doing this on test or development SharePoint servers. To do this, repeat this edit on all servers in your SharePoint farm:
  • Locate the file \15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx and open in a text editor.
  • Add the following element before the existing element with the id of “ID_RequestAccess”:
    <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
     Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
     Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
     MenuGroupId="100"
     Sequence="100"
     UseShortId="true"
     />
  • Save the file.
Now, the menu item shall be displayed:

If you have any questions you can reach out our SharePoint Consulting team here.

VS2012 C# compiler issue solution

If you encounter problem while creating new project in VS2012 or 2013 VM, follow steps given below:
Error: C#2012 compiler could not be created
Solution 1:
Check the following settings: Tools->Options->Text Editor->C#->General->Auto list members
Tools->Options->Text Editor->C#->General->Parameter information
Also check
Tools->Options->Text Editor->C#->Intelligence->
Show completion list after a character is typed
Also,
Tools –> Import and Export Settings -> Reset all Settings
Also,
Instead of changing it for only C#, change it for all the languages
Tools > Options > Text Editor > All Languages
Solution 2:
Run following command on VS2012 x86 Native Tools Command Prompt
gacutil /u Microsoft.VisualStudio.CSharp.Services.Language.Interop
If you are unable to delete the assembly, follow steps given in
http://support.microsoft.com/kb/873195
Solution 3:
Install patch available on path
\\192.168.2.254\Softwares\Microsoft Sharepoint 2013\Other softwares\VS10-KB980610-x86.exe


If you have any questions you can reach out our SharePoint Consulting team here.

Backup/Restore SPWeb programmatically

  • Backup SPWeb Many times we may require to backup SPWeb programmatically. This is the method that can be used to generate backup file of SPWeb. This will generate backup file with ".cmp" extensions and will be stored at specified location.

    //This will create backup file (ABC.cmp) of SPWeb "ABC".
    
    using (SPSite site = new SPSite("http://br76:42319/ABC"))
    
    {
    
    using (SPWeb web = site.OpenWeb())
    
    {
    
    string bPath = "C:\\Backup"; //Location where backup file is to be stored.
    
    SPExportObject exportSite = new SPExportObject();
    
    exportSite.Type = SPDeploymentObjectType.Web;
    
    exportSite.Url = web.Url;
    
    exportSite.IncludeDescendants = SPIncludeDescendants.All;
    
     
    
    SPExportSettings settings = new SPExportSettings();
    
    settings.AutoGenerateDataFileName = false;
    
    settings.BaseFileName = "ABC"; // Name of the backup file.
    
    settings.FileLocation = bPath;
    
    settings.SiteUrl = web.Site.Url;
    
     
    
    settings.ExportMethod = SPExportMethodType.ExportAll;
    
    settings.FileCompression = true;
    
    settings.IncludeSecurity = SPIncludeSecurity.All;
    
    settings.IncludeVersions = SPIncludeVersions.All;
    
    settings.ExcludeDependencies = false;
    
    settings.OverwriteExistingDataFile = true;
    
    settings.ExportObjects.Add(exportSite);
    
    settings.Validate();
    
    SPExport spExport = new SPExport(settings);
    
    spExport.Run();
    
    }
    
    }
  • Restore SPWeb
    This method can be used to restore SPWeb using the backup file of SPWeb.

    //This will create restore web "ABC" from backup file "ABC.cmp".
    
    using (SPSite site = new SPSite("http://br76:42319/ABC"))
    
    {
    
    using (SPWeb web = site.OpenWeb())
    
    {
    
    SPImportSettings settings = new SPImportSettings();
    
    settings.SiteUrl = web.Site.Url;
    
    settings.FileLocation = "C:\\Backup";//Location where backup file is located.
    
    settings.BaseFileName = "ABC.cmp";// Name of the backup file.
    
    settings.UpdateVersions = SPUpdateVersions.Overwrite;
    
    settings.RetainObjectIdentity = false;
    
     
    
    SPImport import = new SPImport(settings);
    
    import.Run();
    
    }
    
    } 

If you have any questions you can reach out our SharePoint Consulting team here.

SharePoint Diagnostic Studio

SharePoint Diagnostic studio is widely used to produce different reports on capacity, performance, usage etc.
The SharePoint Diagnostics Studio provides a wide variety of reports intended to address the most common issues impacting capacity, performance, availability, and usage that can be used independently or together to identify and isolate issues occurring in a SharePoint environment.
SharePoint Diagnostic Studio (SP Diag 3.0) can be used in local farm as well as servers. User should have admin rights to access to view reports. It is also required that user should have access of SQL server database. There are some other configurations required to view proper reports by this tool.
e.g.


  • Microsoft .net frame work 3.5
  • .Net Chart controls for .net frame work 3.5
Follow these steps to configure your project and get different reports.
  • Open SharePoint Diagnostic Studio with admin rights (Run as administrator).
  • You can see home page with menu as shown in above image.
  • Click on new project to configure your server for SharePoint Diagnostic studio.
  • Click on Create project.
  • If you get any error regarding invalid access or cannot access the local farm, then Open SharePoint Management Shell with Admin rights (Run as administrator) and run following Commands.
    • Enable-PSRemoting –force
    • Enable-WSManCredSSP -role Server –force
    • Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000
    • The remotesigned execution policy must be enabled on the farm server
      • Set-ExecutionPolicy RemoteSigned
  • Now Open SharePoint Diagnostic Studio with admin rights (Run as administrator).
  • Create new project again. Now it should create project without any error if you have access of SQL server.
  • If any error occurs regarding Usage Application database, then it indicates you don't have rights to SQL server.
  • Once project is created it will shows a page with different sections as below.
  • Report pane
  • Report Toolbar
  • Report Display pane
  • Filter pane
  • Data Display pane

If you have any questions you can reach out our SharePoint Consulting team here.

Master page configuration based on device

  • Create new empty SharePoint project solution
  • Add new application page in project.
  • Add new c# class file and inherit httpmodule class. Add following code in this class.
     
        ----------------------------------------------------
     
        public void Init(HttpApplication context)
                {
                    context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
                }
         
                void context_PreRequestHandlerExecute(object sender, EventArgs e)
                {
                    Page page = HttpContext.Current.CurrentHandler as Page;
                    if (page != null)
                    {
                        // register handler for PreInit event
                        page.PreInit += new EventHandler(page_PreInit);
                    }
                }
         
                void page_PreInit(object sender, EventArgs e)
                {
                    Page page = sender as Page;
         
                    if (page != null)
                    { 
                        SPSite currentSite = (SPSite)SPContext.Current.Site;
                        SPWeb currentWeb = currentSite.RootWeb;
                        if (page != null)
                        {
                            string strUserAgent = page.Request.UserAgent.ToString().ToLower();
                            Console.Write(strUserAgent);
                            if (strUserAgent != null)
                            {
                                if (page.Request.Browser.IsMobileDevice == true ||
                                    strUserAgent.Contains("iphone") || strUserAgent.Contains("ipod") ||
                                    strUserAgent.Contains("symbian") || strUserAgent.Contains("android") ||  strUserAgent.Contains("htc") ||
                                    strUserAgent.Contains("windows ce") || strUserAgent.Contains("blackberry") ||
                                    strUserAgent.Contains("palm") || (strUserAgent.Contains("mobile") && !strUserAgent.Contains("ipad")) ||
                                    strUserAgent.Contains("opera mini"))
                                {
         
                                    currentWeb.MasterUrl = "/_catalogs/masterpage/Iphone-Device.master";
                                    currentWeb.CustomMasterUrl = "/_catalogs/masterpage/Iphone-Device.master";
                                }
                                else if (strUserAgent.Contains("mobile") && strUserAgent.Contains("ipad"))
                                {
                                    currentWeb.MasterUrl = "/_catalogs/masterpage/Ipad-Device.master";
                                    currentWeb.CustomMasterUrl = "/_catalogs/masterpage/Ipad-Device.master";
         
                                }
                                else
                                {
                                    page.MasterPageFile = "/_catalogs/masterpage/Desktop-Device.master";
                                   
                                }
                            }
                            else
                            {
                                currentWeb.MasterUrl = "/_catalogs/masterpage/v4.master";
                                currentWeb.CustomMasterUrl = "/_catalogs/masterpage/v4.master";
                            }
                            currentWeb.AllowUnsafeUpdates = true;
                            currentWeb.Update();
                            currentWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }
                public void Dispose() { /* empty implementation */ }

  • Create new mater pages as per requirement and upload that master pages in web application.
  • Deploy this solution in web application.
  • Browse the application page and check the functionality in all devices.

If you have any questions you can reach out our SharePoint Consulting team here.

XSLT Debugging with Altova XSLT Spy

​Debugging XSLT with Altova XMLSpy
Testing and perfecting XSLT stylesheets can be a complicated, time-consuming process. With the XMLSpy XSLT debugger, you can step through and debug even the most intricate stylesheets quickly and easily. You can even debug stylesheets that contain program code in Java, C#, JavaScript, or VBScript. When debugging complex XSLT stylesheets, it is useful to be able to understand exactly what output is produced by each instruction. In the XSLT debugger, you can define breakpoints in the XML and XSLT files, and tracepoints in the XSLT document.

Setting Breakpoints & Tracepoints
Breakpoints halt the XSLT debugger when a particular node, element, or attribute is accessed by an XSLT instruction, allowing you to view the output to that particular point in the transformation. When you start the debugger, the XSLT processor stops at the first breakpoint and displays all data relevant to the node in the debugger info windows.
In contrast to breakpoints, tracepoints do not halt the XSLT debugger. When a tracepoint is hit during an XSLT debugging session, the instruction is executed, and information is written to the Trace window. Once the transformation is complete, the trace window displays the list of tracepoints as well as the output produced by each. This allows you to view exactly how each XSLT instruction is executed.

steps:
  • Open the XSLT File in Altova XMLSpy Edito
  • Specify the output XML file
  • Insert break point/Trace point at desired node, attribute or element
  • Review the output in output window
Eg. Search Core Result Web part XSLT Debugging
  • To debug the XSLT, you will need the output XML file. So edit the search core result web part
  • Click on XSL Editor under ‘Display Properties’
  • Copy-Paste following code in editor:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
    <xmp><xsl:copy-of select="*"/></xmp>
    </xsl:template>
    </xsl:stylesheet>
  • Copy the output and save it in an XML File say output.xml
  • Open the XSLT file with Altova XMLSpy editor
  • Set breakpoint/trace point to attribute/node/element
  • Click on XSL/Query menu and select Start Debugger/Go
  • Specify the output.xml file location
  • Start debugging!!!!

If you have any questions you can reach out our SharePoint Consulting team here.