"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:

Author's Profile

My photo
India
A SharePoint Enthusiast working as a Project Lead 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. Apart from being a SharePoint Enthusiasts, I am a husband, a father and a blogger. I love to travel and explore new landscapes and meet people of various culture. I am passionate about learning new technology trends in IT. I love spending time on my fitness and have a deep enthusiasm for urdu poetry and career counseling.

Popular Posts

Powered by Blogger.

Contact Form

Name

Email *

Message *

Total Pageviews