Wednesday 25 May 2016

SharePoint Custom Button to Export list data to Excel.

Process: 

<input type="button" style="width:180px; height: 75px; 30px;background:gray; color:white;font-size:larger; font-weight:bold;"onclick="window.location.href='SITEURL/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={YOUR LIST ID}&View={YOUR VIEW ID}&CacheControl=1';" value ="YOUR BUTTON TEXT"/>


The code above is essentially everything that you will need for a simple Excel Export button.  In order to get the code to work, you will need to update the SITEURL, YOUR LIST ID, YOUR VIEW ID, & YOUR BUTTON TEXT.

How to get these Data:

  • Go to the list which you want to export to Excel.
  • In the ribbon, click on export to Excel.
  • A file will get saved to your local system. 
  • Open the file in notepad.
  • You will get the the List ID and View ID.
  • Go to the particular site and in the URL copy till that site/subsite. This is your Site URL.
Now add all the data to above link and use it in your code.

Example:


 <input type="button" style="width:180px; height: 75px; 30px;background:gray; color:white;font-size:larger; font-weight:bold;"
onclick="window.location.href='http://HostServer00081:3000//_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={FBDA49D4-3206-4408-A5BC-ACC9422D4ADB}&View={F5371271-9A16-46CA-8D57-5B2198587AD9}&CacheControl=1';"
value ="Export to Excel"/>


---

Thanks.

Writing Automated Unit Test Cases and Code Coverage Using Dot Net

To add a new test project 

 1. Right click on the Solution

 2. Add new project ---> Test(Left Side) ---> Unit Test Project ---> Give a name ---> OK

 3. Add the main project dll to the test project
================================================================================================================

Instructions:
==============

1. Use static and private keywords only when it is required. Avoid unnecessary using of these keywords.

2. Which ever the methods are returning void, make them return bool.

3. Make all classes and methods public. Static methods cannot be handled in test cases.

4. Make all the classes and methods public in the test project.

5. The [TestMethod]s should return void. It should not return anything.

6. Try to call all the classes with methods from the main class.
   Test code should be so designed that it should initiate the application from main from
   where it can cover all the classes. This way it will hit most of the lines which will help in code coverage.

7. All the method arguments in the code should be tested.
   Example:
     public bool AddStructureItemsToAnArray(string databaseType, int index, string carModelName, UInt32 CompHash)
        {
            if ((string.IsNullOrEmpty(databaseType)) || (0 > index) || (string.IsNullOrEmpty(carModelName)))
            {
                CDatalogger.SuperTrace("ERROR: Invalid input parametes received");
                return false;
            }
         Logic here
         Logic here
         Logic here
         Logic here
        }

8. Every code should be put in try-catch block and rest things should be captured in finally block.

9. Each error message should be captured in log file through logger class.