"The day you stop learning SharePoint is the day you stop using it."

Remote Debugging a SharePoint 2013 Farm Solution in Visual Studio 2013

Description:
You can remotely debug a SharePoint farm solution in your local Visual Studio without having SharePoint locally installed.

Assumptions:
1. You have a ready on premise SharePoint Server
2. You have Visual Studio 2013 installed on your local machine. (ex. Windows 7/Windows 10)3. You have created identical debug user accounts on both the local host and server machines and add to Local Administrator group on both machines (not sure if admin group is necessary, but better to add it in Administrators group).

Execution in Windows Registry:
1. Go to your SharePoint Server and export 15.0 hive from regedit.exe (Run As Administrator)-[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0]
2. Enter a meaningful name for this exporting file and save.
3. Copy the exported ‘.reg’ file to your local development machine.





4. On your local development machine, open your regedit.exe (Run as Administrator) and navigate to same path [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0] 
5. Select File > Import > Select your copied .reg file and click Open and you are done.

Steps to perform in Visual Studio 2013:
1. Open Visual Studio 2013 as Administrator.
2. Create a new project (I created a SharePoint 2013 – Visual Web Part)
3. In the below wizard, do not change any values, do not click Validate. Simply click Finish.
4. Copy the required SharePoint DLL to your local development machine and add them to References in your VS solution. (I added only Microsoft.SharePoint.dll. You may need more SharePoint DLL depending on SharePoint classes used in your code.)


Configuration Steps:
1. When you are done coding, build the solution and copy pdb file to the SharePoint server. (You will find this pdb file in bin folder)
2. Right click solution and choose Publish. This will create wsp file.
3. Copy this wsp file to the SharePoint server and deploy the solution:
Use Add-SPSolution and Install-SPSolution.
4. Activate the web part from Site Settings and add it to any SharePoint page.
5. Navigate to one of the below location to find your solution folder:
C:\Windows\assembly\ GAC_MSIL\
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
6. Copy the pdb file to your solution folder. Now your solution’s DLL and PDB file are in same folder.
7. On the SharePoint server navigate to [C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Remote Debugger\x64] and run msvsmon.exe as Administrator. You will have below window now running.



8. In the Debugging Monitor window choose > Tools > Permissions and check if the account by which you are running your Visual Studio on your local machine has Debug permission, if not grant it.
9. Open Windows PowerShell on SharePoint Server and run this command:
C:\Windows\System32\inetsrv\appcmd list wp
This command will list all WP process currently running. Note down the WP process ID that you want to attach in Visual Studio. (Example shown below. My Web Part is deployed to 11724, therefore I will choose only this WP ID while attaching to the process in Visual Studio).


Back to Visual Studio 2013:
1. Tools > Attach to Process > Enter “YourDomainName\YourDebugAccount@YourSharePointServerName” in Qualifier field and click Find button.
Example: Octaware\spstp_octaware@tamouh_srv01



2. Choose details returned and press Select.



3. Select “Show processes from all users” and press Refresh button.
4. Among the listed w3wp process, choose the one that you had noted earlier in above step 8.
5. Refresh your SharePoint page and happy remote debugging. (Assuming that your breakpoint is under Page_Load event.)




Share:

Export content of a SharePoint list to a HTML table

You can use SPServices jQuery Library and CAML query to get data from a SharePoint List and display that retrieved data in Content Editor Web Part where you would write your html table code.
To learn more about SPServices refer this: SPServices CodePlex
Before writing the below code in Content Editor Web Part make sure you download jquery-1.4.2.min.js from https://code.jquery.com/jquery/ and SPServices library from http://spservices.codeplex.com/releases/view/119578 and upload both in a document library.
In below code, "GetListItems" operation will get the list items.
Example:
<html>
<head>
<SCRIPT type=text/javascript src="http://MySPSite.com/sites/test/DocLib/jquery-1.4.2.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="http://MySPSite.com/sites/test/DocLib/jquery.SPServices-0.7.2.min.js></SCRIPT>
</head>

<body>
<table id="myHTMLTable" border=1 width="90%" align="center">
                    <tr align='left'>
                    <td><B>ID</B></td>
                    <td><B>EmpName</B></td>
                    <td><B>JobTitle</B></td>
                    <td><B>Department</B></td>
                    </tr>
</table>

<SCRIPT type=text/javascript>

getMyListData() ;

function getMyListData()
{                     
        var method = "GetListItems";                 
        var webURL =  $().SPServices.SPGetCurrentSite() ;                     
        var list = "MyCustomList";                      
        var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
        var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";                       

        $().SPServices
        ({
                    operation: method,
                    async: false, 
                    webURL: webURL,
                    listName: list,
                    CAMLViewFields: "<ViewFields Properties='True' />",
                    CAMLQuery: query,                                                                                     
                    completefunc: function (xData, Status)
                     {
                         $(xData.responseXML).SPFilterNode("z:row").each(function() 
                         {
                              var ID = $(this).attr("ows_ID");
                              var empName = $(this).attr("ows_EmpName");
                              var jobtitle =  $(this).attr("ows_JobTitle");
                              var dept =  $(this).attr("ows_Department"); 

                              $("#myHTMLTable").append("<tr align='middle'>" +
                               "<td align='left'>"+ID+"</td>" +
                               "<td align='left'>"+empName+"</td>" +
                               "<td align='left'>"+jobtitle+"</td>"  +                                         
                               "<td align='left'>"+dept+"</td>" +
                               "</tr>");
                           });
                   }
       });
       };

      </script>
      </body>
      </html>
Share:

Errors while installing SharePoint Server 2013 pre-requisites on Windows Server 2012 R2

You would find tons of blogs discussing the below first error* while installing SharePoint 2013 pre-requisites. I also encountered the second error about .Net framework 3.5.  
  •   Application Server Role, Web Server (IIS) Role: configuration error*
  •  .Net Framework 3.5 not enabled.

The first error was displayed in both pre-requisites tool window (also known as SharePoint Server 2013 Preparation Tool) and the log file which is generated by the tool. While the second error was found only in the log file. So make sure you read the complete log file generated by SharePoint Server 2013 Preparation tool. You should not miss any error that might keep you troubling all the way ahead.



To resolve the first error Application Server Role, Web Server (IIS) Role: configuration error I executed two steps:

1.1 Add Web Server Role and Application Server Role to your Windows Server via Server Manager.
  • Go to Server Manager > Add Roles and Features.
  • Select your server in the Server Pool under Server Selection page.
  • Select Web Server (IIS) Role and Application Server Role.
  • Click Next until the wizard finishes.
1.2   Edit the Local Policy on your Window Server.
  • Run MMC
  • Click File > Add/Remove Snap-in
  • Select Group Policy Object Editor and Add it.
  • Navigate to Administrative Templates > System
  • Double click Specify Settings for optional component installation and component repair.
  • Check the Enabled radio button and select “Contract Windows Update directly to download repair content instead of Windows Server Update Services (WSUS) check box”.

To resolve the second error .Net Framework 3.5 not enabled you must add .Net Framework 3.5 feature via Server Manager > Add roles features.
  • In Server Manager, click Manage and then select Add Roles and Features to start the Add Roles and Features Wizard.
  • On the Select installation type screen, select Role-based or feature-based installation.
  • Select the target server.
  • On the Select features screen, check the box next to .Net Framework 3.5 Features.
  • On the Confirm installation selections screen, a warning will be displayed asking Do you need to specify an alternate source path? If the target computer does not have access to Windows Update, click the Specify an alternate source path link to specify the path to the\sources\sxs folder on the installation media and then click OK. After you have specified the alternate source, or if the target computer has access to Windows Update, click the X next to the warning, and then click Install.
  • If you are using Server Manager in Windows Server 2012 to add a role or feature to a remote server, the remote server’s computer account (DOMAIN\ComputerName$) requires access to the alternate source file path because the deployment operation runs in the SYSTEM context on the target server.
Reference: https://technet.microsoft.com/en-us/library/dn482071.aspx

These were the two resolutions I implemented, restarted the server and re-ran the pre-requisites tool and got everything working fine. Hope this helps you.
Share:

Add Date Time automatically in SharePoint Blog Post

In this post we would be discussing on how we can disallow users to select the Published (Date-Time) field while creating a blog post in SharePoint. Like below:


Our aim is to set the Published automatically as per the current system's date-time.
If you are thinking to follow the usual way of hiding fields from the list form then you are not thinking about the impact it would have. I am talking about the below steps:

Go to the Advanced Settings of this list, set Allow Management of Content Types equal to Yes. Click on the Post content type, click on the Published column, and select Hidden.

The user will no longer have the option to set the published date/time. Note that it will still be set, but will be set the default current time.
The above two steps will land you in trouble and your blog's date-time will not be visible on blog post, even in list view. To tackle this issue there is a trick here to get the date-time on the post without Published field being available to the user.
Create a SPD workflow to publish on Post list. In this workflow simply create one step to update thePublished field value with Modified field value as show in below image. Ensure to only select "Start the workflow automatically when an item is created" at the Start Options in SPD.
Now create a post after publishing the workflow and you will see the date-time on your post and even in the list view with Published column being unavailable to the author.
Share:

Working with SharePoint 2010 Content Query Web Part & XSLT to create custom event date calendar

I was assigned to create an Event Calendar Display web part that may show employees leave plans in the IT department. I created the web part with the help of this awesome article http://labs.steveottenad.com/sharepoint-2010-xslt-date-formatting/ and I achieve what I needed. Later I felt the need of adding paging to the web part and started researching for it and came across below another awesome article references mentioned in point 3 and 5. Thanks to all the authors for doing this wonderful job.
  1. I Opened SPD and copied ContentQueryMain.xsl and ItemStyle.xsl from XSL Stylesheet folder to a custom folder, while keeping both default xsl files unchanged.
  2. I copied the xsl code and css code given in this article SharePoint 2010 XSLT date formatting to create the customized event calendar "Upcoming Events" (as shown in article) to my copied ItemStyle.xsl file. (Read the whole article and you will understand how you can perform this step).
  3. Download: ImtechContentQueryWebPart.wsp custom web part from this link:http://imtech.codeplex.com/ [This web part is a custom Content Query Web Part through which you can apply your own xsl files).
  4. Install the ImtechContentQueryWebpart to your SharePoint server and activate it through site collection features in Site Settings.
  5. Now go step by step and make changes again to your copied ItemStyle.xsl and ContentQueryMain.xsl files as explained in this article: Retro-fitting existing XSL Stylesheets with the Paging Controls
  6. The author in the article referenced in point 5 has pasted the code below <xsl:template name="Default" match="*" mode="itemstyle"> Instead a I posted the code below this line<xsl:template name="EventDisplay" match="Row[@Style='EventDisplay']" mode="itemstyle">The above line having EventDisplay you will find in your copied & edited ItemStyle.xsl file. Simply search the term EventDisplay and you will get it.
    Finally insert the Imtech Content Query Web Part to your page and copy the path of copied ItemStyle.xsl and ContentQueryMain.xsl files. Paste these paths as shown below in first image:
    enter image description here
    And the final result you get is: [*Please note the Leave Type and Click Here is appearing due to my own customized code in ItemStyle.xsl. Rest the output is same as shown in article referenced in point 2.]
    enter image description here

I am posting my retrofitted custom ItemStyle.xsl which I managed to create with above steps. I am posting an extract of my ItemStyle.xsl below that would help in adding Leave Type and Click Here.
-First create a Leave Type drop-down column in your SharePoint Calendar List and also create a simple text column CalendarLink having a default value as "http://yoursiteURL,Click Here". This value would be created for every item you enter in SharePoint Calendar List. In Leave Type column enter any values like Annual Leave, Medical Leave or just anything of your choice.

If you observe my below code attentively then you will make out how I have referenced Leave Type and CalendarLink columns in the code. If you have any doubts or face any challenge, feel free to leave a comment and I will surely love to respond.

You can even copy my below code to your custom ItemStyle.xsl and get the job half done. Rest you should take care of ContenQueryMain.xsl, and Custom Columns.

Thank you for reading this article and making my effort feel worth it !


<xsl:template name="EventDisplay" match="Row[@Style='EventDisplay']" mode="itemstyle">  
   <xsl:param name="CurPos" />  
      <xsl:variable name="dateTime" select="ddwrt:FormatDate(string(@EventDate), 1033, 3)" />  
      <xsl:variable name="dateTimeCondensed" select="ddwrt:FormatDate(string(@EventDate), 1033, 2)" />  
      <xsl:variable name="date" select="substring-before(substring-after($dateTime, ', '), ', ')" />  
      <xsl:variable name="month" select="substring-before($date, ' ')" />  
      <xsl:variable name="day"  select="substring-after($date, ' ')" />  
      <xsl:variable name="time" select="substring-after($dateTimeCondensed, ' ')" />  
      <xsl:variable name="SiteLink" select="substring-before(@CalendarLink,',')"/>  
   <xsl:variable name="SiteName" select="substring-after(@CalendarLink,',')"/>  
   <xsl:variable name="LeaveData" select="concat($SiteLink,'/dispform.aspx?ID=',@ID)"/>  
      <xsl:variable name="SafeLinkUrl">  
           <xsl:call-template name="OuterTemplate.GetSafeLink">  
              <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>  
           </xsl:call-template>  
      </xsl:variable>  
      <div class="item link-item">  
           <div class="description xslCal">  
                <div class="left">  
                     <span class="month"><xsl:value-of select="$month" /></span>  
                     <span class="day"><xsl:value-of select="$day" /></span>  
                </div><!--/Left-->  
                <div class="right">  
                     <span class="title"><xsl:value-of select="@Title" /></span><br/><br/>  
               <span class="Category">Leave Type: <xsl:value-of select="@Category" /></span>  
             </div><!--/Right-->  
           </div><!--/description-->  
      </div><!--/item-->  
      <a href="{$LeaveData}"><xsl:value-of select="$SiteName"/></a>  
        <xsl:if test="$PageSize &gt; 0">  
          <xsl:variable name="NumPages" select="ceiling($TotalRecords div $PageSize)"/>  
          <xsl:variable name="PageBeforeLast" select="$NumPages - 1"></xsl:variable>  
          <xsl:variable name="CountBeforeLastPage" select="$PageBeforeLast * $PageSize"></xsl:variable>  
          <xsl:variable name="LastPageCount" select="$TotalRecords - $CountBeforeLastPage"></xsl:variable>  
            <xsl:if test="$PageNumber = $NumPages and $CurPos = $LastPageCount">  
               <br/>  
               <xsl:call-template name="PagingControls">  
                <xsl:with-param name="Page" select="1" />  
                <xsl:with-param name="NumPages" select="$NumPages" />  
               </xsl:call-template>  
            </xsl:if>  
            <xsl:if test="$CurPos = $PageSize and $NumPages &gt; 1 and $PageNumber != $NumPages">  
             <br/>  
             <xsl:call-template name="PagingControls">  
              <xsl:with-param name="Page" select="1" />  
              <xsl:with-param name="NumPages" select="$NumPages" />  
             </xsl:call-template>   
          </xsl:if>  
        </xsl:if>  
      </xsl:template>  
      <xsl:template name="PagingControls">  
   <xsl:param name="Page" />  
   <xsl:param name="NumPages" />  
   <xsl:if test="$Page = 1">  
    <xsl:text disable-output-escaping="yes"><![CDATA[<div>]]></xsl:text>  
    <xsl:if test="$PageNumber &gt; 1">  
     <xsl:variable name="PreviousPageNo" select="$PageNumber - 1"/>  
     <a href="?{$PagingParameterName}={$PreviousPageNo}">  
      <xsl:text disable-output-escaping="yes"><![CDATA[&laquo;]]></xsl:text> Prev  
     </a>  
     <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>  
    </xsl:if>  
   </xsl:if>  
   <xsl:choose>  
    <xsl:when test="$Page = $PageNumber">  
     <strong>  
      <xsl:value-of select="$Page"/>  
     </strong>  
    </xsl:when>  
    <xsl:otherwise>  
     <a href="?{$PagingParameterName}={$Page}">  
      <xsl:value-of select="$Page"/>  
     </a>  
    </xsl:otherwise>  
   </xsl:choose>  
   <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>  
   <xsl:if test="$Page &lt; $NumPages">  
    <xsl:call-template name="PagingControls">  
     <xsl:with-param name="Page" select="$Page + 1"/>  
     <xsl:with-param name="NumPages" select="$NumPages" />  
    </xsl:call-template>  
   </xsl:if>  
   <xsl:if test="$Page = $NumPages">  
    <xsl:if test="$PageNumber &lt; $NumPages">  
     <xsl:variable name="NextPageNo" select="$PageNumber + 1"/>  
     <a href="?{$PagingParameterName}={$NextPageNo}">  
      Next  
      <xsl:text disable-output-escaping="yes"><![CDATA[&raquo;]]></xsl:text>  
     </a>  
    </xsl:if>  
    <xsl:text disable-output-escaping="yes"><![CDATA[</div>]]></xsl:text>  
   </xsl:if>  
  </xsl:template>  



Share:

SharePoint-StackExchange Moderator

Author's Profile

My photo
India
A SharePoint Enthusiast working as a Lead Solution Architect for an IT Software & Consulting Company in Mumbai. I believe in giving back to the community through which I also learn and develop and eventually grow as an individual and professional. This blog is a small contribution to the community where I live in and may help someone who is seeking knowledge like me.

Popular Posts

Powered by Blogger.

Contact Form

Name

Email *

Message *

Total Pageviews