Search This Blog

Thursday, July 11, 2019

How to open Documents in Browser in SharePoint classic view

In SharePoint, Microsoft provides the below URL format to meet the user's expectation.

The URL format you are looking for is,

<SiteURL>/_layouts/15/WopiFrame.aspx?sourcedoc=<Doc URL>&file=<File Name>&action=default";



<script  type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>    
        
<script  type="text/javascript"> 
    (function () {
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides({  
            Templates: {  
                Fields: {  
                    'LinkFilename': {  
                        'View': function (ctx) {  
                            var currentVal = '';  
                            //from the context get the current item and it's value   
                            if (ctx != null && ctx.CurrentItem != null)  
                                currentVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];  
                  
                            if(ctx.CurrentItem.File_x0020_Type == "pptx"||ctx.CurrentItem.File_x0020_Type == "pdf" ||ctx.CurrentItem.File_x0020_Type == "xlsx" ||ctx.CurrentItem.File_x0020_Type == "docx" ||ctx.CurrentItem.File_x0020_Type == "doc"){  
                                el = "<div><a id="+ctx.CurrentItem.UniqueId+" class='ms-listlink ms-draggable' onclick='OpenFileInModal(this);return false;' href='" + ctx.CurrentItem.FileRef + "'>" + ctx.CurrentItem.FileLeafRef + "</a></div>";  
                            }else  
                            {  
                                el = "<div><a id="+ctx.CurrentItem.UniqueId+" class='ms-listlink ms-draggable'  href='" + ctx.CurrentItem.FileRef + "'>" + ctx.CurrentItem.FileLeafRef + "</a></div>";  
                            }  
                            // Render the HTML5 file input in place of the OOTB  
                            return el;  
                        }  
                    }  
                }  
            }  
        });  

    })();

function OpenFileInModal(sender) {  
    var options = SP.UI.$create_DialogOptions();  
    var documentID=$(sender).attr('id');       
    var str=_spPageContextInfo.webAbsoluteUrl +"/_layouts/15/WopiFrame.aspx?sourcedoc=" + documentID + "&file="+sender.text+"&action=default";     
    //Using a generic object.  
    var options = {  
        title: "",  
        width: 1000,  
        height: 1200,  
        url: str  
    };  
  
    SP.UI.ModalDialog.showModalDialog(options);  
}  
</script>  

Tuesday, June 25, 2019

Enable Site Collection App Catalog For Particular Site Collection Level Solution/Features

In this article, we will learn how to enable site collection app catalog. By enabling the site collection level app catalog (not the tenant), we can deploy/install SharePoint AddIn/SPFx solutions at the site collection level. Consider this like sandbox solution, as a component is only deployed and is installed on the site collection and not available for other site collections.



Why do we need a Site Collection App Catalog?


There are times and cases when we, as a developer, have to build a solution which is very much specific to a particular project or application. This solution demands a very determined approach to solving a specific problem which is not required for other site collections of your tenant. Below are some of the reasons why we need a site collection app catalog. 


  • Provide isolated and focused solution/web part for a particular project.
  • Tenant level App/Add-in is visible to all site collection under a tenant. Risk of installing the app in other site collections is nullified for which solution is not required.
  • Provides controls to Site collection admins to manage solutions specific on site collection.
  • No need to provide access to site collection admins to deploy the app on the tenant.
  • Saves times and faster deployment methodology.
  • How to enable site collection app catalog?


Notes

This is a one-time activity to be done by tenant admins.  

open SharePoint Online Management Shell.

Connect to the Tenant.
Connect-SPOService -Url https://wayneenterprise-admin.sharepoint.com -credential bruce@wayneenterprise.com
Connect to the particular site and run Add-SPOSiteCollectionAppCatalog.
# get a reference to the site collection where the  
# site collection app catalog should be created  
$site = Get-SPOSite https://wayneenterprise.sharepoint.com/sites/justiceleague
 # create site collection app catalog  
Add-SPOSiteCollectionAppCatalog -Site $site

Once you go to the site collection, you will see the app for SharePoint library which can be used to deploy the app. 


Source : https://www.c-sharpcorner.com/article/enable-site-collection-app-catalog-for-particular-site-collection-level-solution/

Thursday, April 11, 2019

Comparison (cookies vs cache), (PUT vs POST) && (JSLink vs Script Editor vs Content Editor WebPart)

cookies vs cache

Cookie should be used to store per-user information for the current Web session or persistent information on the client, therefore client has control over the contents of a cookie.

Cache object is shared between users in a single application. Its primary purpose is to cache data from a data store and should not be used as a primary storage. It supports automatic invalidation features.

PUT vs POST

The most commonly used HTTP verbs POST, GET, PUT, DELETE are similar to CRUD (Create, Read, Update and Delete) operations in database. We specify these HTTP verbs in the capital case. So, the below is the comparison between them.

create - POST
read - GET
update - PUT
delete - DELETE
PATCH: Submits a partial modification to a resource. If you only need to update one field for the resource, you may want to use the PATCH method.

JSLink vs Script Editor vs Content Editor WebPart

1. JSlink: you can control rendering of Fields, Items and even Web Parts using a JavaScript File referenced in JS Link property field of a Web Part.

2.  Script Editor Web Part: you could paste your html and JavaScript into Script Editor Web Part. And it is a reusable one.

3. Content Editor Web Part: you could add formatted text, tables, hyperlinks, and images to a Web Part Page by Content Editor Web Part.

Difference between Sandboxed and Farm solution

In this post we will see the difference between Farm solutions and Sandboxed solutions 

Farm solutions, which are hosted in the IIS worker process (W3WP.exe), run code that can affect the whole farm. 

Sandboxed solutions, which are hosted in the SharePoint user code solution worker process (SPUCWorkerProcess.exe), run code that can only affect the site collection of the solution.Farm solutions are installed and deployed. Sandboxed solutions are uploaded and activated.

Embed code and script editor webpart in SharePoint 2013

In this post, we will discuss some difference between the Embed code and Script editor web part in SharePoint 2013.

Both Embed code and Script editor web part are new in SharePoint 2013. You can include JavaScript and HTML contents through the Embed Code which you will get when edit a site page and this is located under Insert Tab in the Ribbon.

Script editor web part also you can use to paste your HTML and JavaScript into the page. But it is a reusable one. The difference between these two is Embed code is not reusable.

Another major difference between these two is Embed code allows you to place the Iframe elements but Script Editor Web Part doesn’t allow. So Youtube, Twitter or LinkedIn or Facebook code you can paste through Embed Code.

Wednesday, April 10, 2019

How To Get All SharePoint List Item Versions Using CSOM For Custom List And Document Library

In CSOM, basically, there is no direct property to get the versions of the items in a List. By using "Lists Web Service"(/_vti_bin/Lists.asmx), however, we can get the information of all the versions and properties of each item inside a Custom List or a Document Library.
To get the above-required functionality, first of all, we have added the "Lists Web Service" in the required project.
In this blog, I am going to share all the codes for getting the version details of list items by using "Lists Web Service". We all know how to add a service to a project.
We are using the below code to achieve the same. The code is self-explanatory because of the comments I have written before each snippet.

Source Code

using System;
using System.Net;
using System.Xml;
using Microsoft.SharePoint.Client;
namespace ConsoleAppTest {
    class Program {
        static void Main(string[] args) {
            ClientContext context = null;
            List list = null;
            ListItemCollection itemCollection = null;
            ListItem item = null;
            string userName = string.Empty;
            string password = string.Empty;
            string dateHistory = string.Empty;
            string commentHistory = string.Empty;
            string editor = string.Empty;
            string loginName = string.Empty;
            try {
                using(context = new ClientContext("https://Testsite.sharepoint.com")) {
                    userName = "UserName";
                    password = "PassWord";
                    // Setting credential for the above site
                    context.Credentials = new SharePointOnlineCredentials(userName, password);
                    context.Load(context.Web);
                    context.ExecuteQuery();
                    // Getting list by Title
                    list = context.Web.Lists.GetByTitle("List Title");
                    context.Load(list, L => L.Id);
                    // Getting all items from selected list using caml query
                    itemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
                    //Loading selected list items
                    context.Load(itemCollection, IC => IC.Include(I => I.Id, I => I.DisplayName));
                    context.ExecuteQuery();
                    if (itemCollection != null && itemCollection.Count > 0) {
                        for (int iCount = 0; iCount < itemCollection.Count; iCount++) {
                            try {
                                item = itemCollection[iCount];
                                ListService.Lists listService = new ListService.Lists();
                                listService.Url = context.Url + "/_vti_bin/Lists.asmx";
                                listService.Credentials = context.Credentials;
                                //Getting all item versions from custon list item using List Web Service
                                XmlNode nodeVersions = listService.GetVersionCollection(list.Id.ToString(), item.Id.ToString(), "_UIVersionString");
                                //looping all versions and getting 'Modified' and 'Editor' property of each version
                                foreach(XmlNode xNode in nodeVersions) {
                                    try {
                                        dateHistory = xNode.Attributes["Modified"].Value;
                                        dateHistory = FormatDateFromSP(dateHistory);
                                        commentHistory = xNode.Attributes["_UIVersionString"].Value;
                                        loginName = xNode.Attributes["Editor"].Value;
                                    } catch {}
                                }
                            } catch (Exception ex) {}
                        }
                    }
                }
            } catch (Exception ex) {}
        }

        private static string FormatDateFromSP(string dateHistory) {
            string result;
            result = dateHistory.Replace("T", " ");
            result = result.Replace("Z", "");
            return result;
        }
    }
}   

Tuesday, April 9, 2019

Site Pages and Application Pages in SharePoint 2013

Site Pages
  
                   These Pages are stored in the Content Database and they are parsed when requested by user. A typical web part page is an example of Site Pages. They can be edited, modified by the Power Users and customized according to their needs.

Application Pages

                  They are same as ASP.net Pages and stored on the layouts folder of SharePoint front end web server. When user requests , application pages are compiled and they are much faster than Site Pages. Admin Pages like settings.aspx, accessdenied.aspx are an example of Application Pages. Thus we can say that Application pages are common to all SharePoint Users.