Tuesday, March 24, 2015

Enable Auditing for a specific document library and list.


Environment: SharePoint 2013 Enterprise
Requirement:
  • Enable audit for a document library to get the number of times the document is opened
  • Enable audit for a list to get the total number of times the item is edited.
Solution/Steps:
  1. Go to Document library > Settings > Library Settings
  2. Click Information management policy settings
  1. Click on Document under Content Type
  2. Provide the necessary details and select “Opening or downloading documents, viewing items in lists, or viewing item properties” under Enable Auditing
  1. Click OK
  2. Navigate to the list where you want to set the policy
  3. Click List Settings > Select Information management policy settings

  1. Select the List from the policy settings
  2. Provide the required details and select Editing items under Enable Auditing

  1. To view the report, navigate to the top level site and Site Settings
  2. Select Audit log reports under Site Collection Administration

  1. Click Run a custom report under Custom Reports section

  1. Select the required events to view the report for

  1. Click Ok
  1. Click on “Click here to view the report”


Note: Site collection administrators page views or edit are not tracked.

Wednesday, March 18, 2015

Create and associate multiple content types for a library

Environment: SharePoint 2013
Requirement: Create multiple content types for a document library to have different metadata/columns.
Introduction: The following steps are to create sample content types to store Budget and Invoice details in a document library.
Solution:
Create a site content type named ’Budget’. The parent content type can be selected based on the requirement. For example, if you are settings this for a document library then use Document Content Type as parent and if you setting this for a list, then select List content type.


Add columns that are specific to the created content type.
Create another content type named ‘Invoice’
Add columns that are specific to Invoice content type.




Navigate to the document library where you want to associate this content type.
Click Library > Library Settings > Advanced Settings and allow management of content type.


Associate the Budget and Invoice content types to the library in Library Settings page.


After associating the content types, you can see the content type column when you add a new item in the document library. The column that are created for each content type will get displayed based on the 
content type you select.


Upload document and submit metadata for different content types.

Monday, February 23, 2015

Programatically increase security validation timeout for a web application in Sharepoint

Environment: SharePoint Server 2013

Requirement: Programatically increase security validation timeout for a web application in SharePoint

Solution: The following line of code will set the Web Page Security Validation expiry to 60 minutes

   SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://webappURL/"));

   //Use TimeSpan constructor to specify Days, hours, minutes, seconds
    webApp.FormDigestSettings.Timeout = new TimeSpan(1, 0, 0); 

  //Save the changes 
    webApp.Update();

NoteYou'll get access denied error when the above code is executed within RWEP as it runs the code under the Application Pool account of the your web application. You need to run this code with farm account as the SPWebApplication is stored in config database. Use SPUserToken and farm account to run this code.

Wednesday, February 4, 2015

OpenSSL - No such file or directory

Scenario: Trying to convert csr certificate to crt using OpenSSL and getting following error
Command used: OpenSSL> x509 -req -in server.csr -signkey server.key -out server.crt

Issue: 
Loading 'screen' into random state - done
server.csr: No such file or directory
error in x509

Resolution:
Provide full path for both .csr and .key file to run this command successfully.

Sunday, January 4, 2015

Unable to add iframe in Content Editor WebPart SharePoint 2013 & IE 11

Using SharePoint 2013, IE 11

Issue: Cannot add iframe in Content Editor WebPart. Source page added in iframe is not getting displayed in IE 11. Works fine in Firefox and chrome browsers.

Script used: <iframe  id="iFrameBox" src="http://servername.com/page.html"></iframe>


Resolution: Add the script to load the source file on document ready function.

<script language="javascript" type="text/javascript">
 $(document).ready(function(){
       $("#iFrameBox").attr("src","
http://servername.com/page.html");
 });

</script>

<iframe  id="iFrameBox" src=""></iframe>

Tuesday, November 25, 2014

Too many characters in character literal

Issue: Getting "Too many characters in character literal" error when try to build a SharePoint project. Error in the following line of code in application page
Assembly Name="$SharePoint.Project.AssemblyFullName$"

Cause: Since the SharePoint project is a sandboxed solution, Sandboxed solutions do not support the application pages.
Referencehttp://msdn.microsoft.com/en-us/library/ee231562.aspx

Resolution: Fixed it by changing the solution from Sandbox to farm.

Thursday, September 4, 2014

Remove duplicate Array from JArray

To remove duplicate array from JArray.


private static string RemoveDuplicateTasks(JArray strArray)
        {

            JArray uniqueArray = new JArray();
            StringBuilder jsonResponse = new StringBuilder();

            //Loop through each array and find for array value with a specific column name. (ex: ID)
            foreach (JObject jObject in strArray)
            {
                //Verify if the ID column value exist in the uniqueArray
                JObject rowObject = uniqueArray.Children<JObject>().FirstOrDefault(o => o["id"] != null && o["id"].ToString() == jObject.Property("id").Value.ToString());

                //rowObject will be null if these is no match for the value in ID column
                if (rowObject == null)
                {
                    uniqueArray.Add(jObject);
                }
            }

            //Remove the curly braces { }
            int strLength = uniqueArray.ToString().Length;
            string strValue = uniqueArray.ToString().Substring(1, (strLength - 2));
            jsonResponse.Append((jsonResponse.Length > 0 ? "," : "") + strValue);
            return "[" + jsonResponse.ToString() + "]";
        }