How to find Created Date and Size of a Subsite in SharePoint


In this article, let us see how to find when a subsite is created and what is the size of the subsite in SharePoint

Steps:

  • Go to a document library in subsite (or top level site) and click on “Open with Explorer as shown below

Open with Explorer

  • This will open the explorer window with subsite library contents as shown below. Click on the top site name(in my case, MngsvcsCollab) to show the top site contents.

Sub site in Explorer window

  • Right click on subsite for which you want to find the Created Date and Size and click on Properties

Top site contents

  • In Properties window, you can see the size of subsite as 34.8 MB and Created as June 22,2017.

Sub site Properties

That’s it. This method can also be used to find when a list or library is created and size of it in SharePoint.

Advertisements

Hide items after 90 days without using workflows


We always prefer “Pause until Date” in SharePoint Designer workflow to delete the items or to hide the items after 90 days. In this post, I will show you how to hide the items without using SharePoint designer workflow.

  • Create a Calculated column in list (Say, Is90days) with the formula, =Created+90 with Date as return type as shown below

  • Create a standard view called, Myview with the below filters
    • CreatedBy=[Me] to show only their items.
    • Is90days>=[Today] to show the items only till 90 days from the creation date.

 

NOTE: If you have sensitive data and you are afraid that they might switch the view to see all the items, you may target the audience for the list web part with all the items.

How to check-in multiple files at once


SCENARIO:

When you have a mandatory column in document library and when you upload multiple files and folders in it using “Open with explorer” option, all the files either within or without folders will be checked out by default.

Checked Out Files

When you try to check-in the file, it will prompt you to fill out all the required properties before checking in the file.

SOLUTION:

How to fill out the properties for multiple files(including the files within folders):

  • Click on Library in the ribbon and click “Create View” under Manage Views
  • Choose Datasheet view, give a name(say, Properties view) and check the boxes under Columns for Type, Name and the mandatory columns
  • Expand the folder and choose “Show all items without folders”and click OK button.

Folder Options

  • Now, fill out the values for mandatory column in properties view

Properties View

  • Stop editing this list

How to Check-in the files:

  • Go to Properties view and switch to Standard view
  • Select all the documents using ‘Tick Mark” behind Name column
  • Click on Files tab in the ribbon and select “Check In” under “Open & Check Out”

Check In.png

Alternative ways to check in multiple files in Publishing sites:

If you have at least edit permission in a publishing site, you can use the below method:

  • Go to Site Settings and click on “Content and Structure” under Site Administration
  • Change the view from “Default View” to “Checked Out To Me” as depicted below:

Content and Structure - Checked Out to Me.png

  • Select all the documents, go to Actions and select “Check In” as shown below

Content and Structure - Check In.png

That’s it!

SharePoint REST API results in browsers


Rest api results for SharePoint lists can be seen in Google Chrome in xml format.

What if you don’t have Chrome and still interested in viewing results ?

To view results in IE:

Feed in IE

  • Go to Settings and click on Internet Options

IE options

  • Click on Settings under Feeds and Web Slices in Content tab and uncheck the turn on feed reading view box.

Settings

  • You will see the results in Xml format as shown below:

xml

To view results in Mozilla Firefox:

  • Open Firefox and type the rest url. You will see the same feeds page as IE

Firefox feed

Result in firefox

Advantages of viewing results in browsers:

  • You can immediately verify the rest operation results
  • You can find the column name to use it in rest operation

Exclude AllItems.aspx from Search Results in Content Search Web Part


When I was working with Content Search web part in one of my SharePoint sites, I experienced a problem where the search result for list items is displayed along with list views.
In this article, I will show you how to remove the list views in CSWP search results.
For better understanding, consider a list, EMPINFO from which you want to show the items in CSWP. To show specific list items, you might have carried out the below steps

  • Edit the CSWP and click on Change query

  • Choose Documents (System) in Select a query
  •  Choose Specify a URL and enter the list URL for Restrict by app

  • Switch to Advanced mode and remove the highlighted file extension query text.

  • You can see AllItems.aspx view along with the list items in search results.

To remove the view, you can follow any one of the below step:

  • Select “Only return items “ in keyword filter and click on “Add Keyword Filter”
  •  Just append [contentclass:STS_ListItem] after Path in Query text

Upgrading SharePoint App


Whenever you make changes and redeploy the app, data that were created previously by the app will be lost. To make changes in the app without losing the data, you need to upgrade the app.

Let us see how to upgrade the app:

  • Open AppManifest.xml and increment the version number by 1 whenever a change is made
  • In my case, version is 1.0.0.2. Hence I am changing it to 1.0.0.3 and publishing the app as shown below:

Publishing app

  • Click on Finish in Publish summary.

Publish summary

  • Explorer window opens as depicted below:

Published app version

  • Copy the location of the file and go to the developer site
  • You can see the list of apps in App Testing. Select the app and click on upgrade an app

Upgrade

  • Click on Upload and browse the file from copied location

Upgrade - Upload

  • Click on Upgrade

Upgrad - Complete

  • You can see the upgrade progress as shown below:

Upgradeinprogress

  • Once upgraded, the version is changed to 1.0.0.3 and if you check for the previous data, it actually exists.

That’s it!

Reference: http://www.c-sharpcorner.com/article/upgrade-sharepoint-hosted-add-insapps-in-sharepoint-2013/

 

PART 2 : SharePoint-Hosted App


Have you read PART 1? Cool. Continue reading how to create an app in host web.

Let us see the same create operation for better understanding. We need two URLS for this:

  • HostURL
  • AppWebURL

To retrieve the URLS, QueryStringParameter() is generally used. But this does not work in all the cases especially when we move from one page to another in app web. So, let’s use the below one:

  • appWebUrl = window.location.protocol+”//”+window.location.host+_spPageContextInfo.webServerRelativeUrl;
  • hostUrl = _spPageContextInfo.siteAbsoluteUrl;

To change the context site from app web to other sites, AppContextSite() is used. To change the current context(i.e, app web) to host web, pass it as
var appctx = new SP.AppContextSite(ctx, hostUrl);

Let’s combine all these with previous code. Here you go:

var appWebUrl;
var hostUrl;
$(document).ready(function ()
 {
appWebUrl = window.location.protocol+"//"+window.location.host+_spPageContextInfo.webServerRelativeUrl;
hostUrl = _spPageContextInfo.siteAbsoluteUrl;
 $("#create").on('click', function ()
 {
                createList();
  });
});
//create List
function createList()
 {
    var listTitle = $("#listName").val();
    var ctx = new SP.ClientContext(appWebUrl);
    var appctx = new SP.AppContextSite(ctx, hostUrl);
    var oweb = appctx.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(listTitle);
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
    oweb.get_lists().add(listCreationInfo);
    ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() 
{
    alert("List Created");
}
function onQueryFailed(sender, args) {
    alert("Operation Failed" +"\n"+ args.get_message());
}

After deploying the app, when you create the list, the below error is shown

Access Denied for Host Web

  • This is because to access or create resource in host web, we need to give FULL CONTROL permission for web and list. To give permission, open AppManifest.xml, move to permission tab and give the permission as shown below:

Fullconrol Permission

  • Now when you deploy it, you will get the below page:

Trust the app

  • Click on trust and create a list using the app. List is created in the host web and can be seen in the site contents page.

If you have noted that when you deployed the app again after making some changes, the data created previously were lost. Continue reading the next article, Upgrading SharePoint app to learn how to deploy the app without losing the data.

PART 1: SharePoint-Hosted App


Apps for SharePoint are also called as SharePoint Add-ins. In SharePoint 2013, everything is considered as an app. Lists, libraries are all called as apps. Apps can be hosted

  • In SharePoint farm (SharePoint-hosted)
  • In separate server(Provider-hosted)
  • In cloud(Auto-hosted)

SharePoint-Hosted App:

It includes only SharePoint components. SharePoint Site where the app is installed is called Host web. All the resources such as list, libraries are in isolated sub site called App web.

Let us create a SharePoint-hosted app to create a list in SharePoint On-Premise environment.

  • Run Visual Studio as administrator and click on File->New->Project

New Project

  • Select Apps for SharePoint 2013 and give a name(say, createListinHost) and hit ok button

Host

  • Next, Specify the site url ( say,Developer site), select the type as SharePoint Hosted and click on Finish

SharePoint Hosted app

  • App is created and default aspx page is shown.

Default aspx

  • Replace the highlighted code with the below one to create a textbox and button for create operation.

<label for=”listName”>List Name to be created</label>
<input type=”text” id=”listName” Placeholder=”Enter the listname”/>
<input type=”button” id=”create” value=”Create”/>

  • Branding(Optional):
    • You can change the title of the page in
      <asp:Content ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea” runat=”server”> List Creation </asp:Content
    • You change the icon for app in AppManifest.xml. Open AppManifest and change the image for Icon. Image should be of 96*96 pixel

App Icon

  • To insert create functionality in this app, expand Scripts, open App.js and insert the below code:
$(document).ready(function () 
{ 
    $("#create").on('click', function () {
                createList();
    });
});
//create List
function createList()
{
    var listTitle = $("#listName").val();
    var ctx = SP.ClientContext.get_current();
    var oweb = ctx.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(listTitle);
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
    oweb.get_lists().add(listCreationInfo);
    ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() {
    alert("List Created");
}
function onQueryFailed(sender, args) {
    alert("Operation Failed" +"\n"+ args.get_message());
}
  • Press F5 or click on Solution->Deploy to deploy the code. Default aspx page will be opened in browser. If not go to the site->Site Contents and click on the app, “createListinHost”

App in Site Contents

  • Create a list say, Sample

 

Below page is shown where you can see that sample list created under “createListinHost”

Sample list settings

Site lists and libraries

Now, question arises. Should all the resources reside in app web only? What If I need to create a resource or access a resource that is in host web? Can I do it? Yes, you can create and access resources in host web. Continue Reading in PART 2

Comparing Dates in SharePoint


SCENARIO:

Let us assume that we need to hide some fields in SharePoint form based on other field value such as text box, what will we do? We will just check the value of the field on page load in edit form as shown below:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
{
if($("input[title='Title']").val()=="Text1") 
{
//hide fields
} 
});
</script>

This is pretty much simple. But assume that we need to hide some fields based on date and time value where Date and Time field is split into three controls:

  • Text box for Date along with Date Picker
  • Dropdown box to select Hours
  • Dropdown box to select Minutes

On seeing the three controls, we may think it is very complicated. Certainly not. We are going to achieve this by retrieving the id of date textbox and then append the id with the words, “Hours” and “Minutes” to get the value of Hours and Minutes dropdown. So, this will be quite interesting. Let’s start.

Retrieving value from Date and Time field:

The below code shows how to retrieve value from date and time field in edit form on page load. If we need to check the value of date and time field in new form on save button for some other requirement, use PreSaveAction function instead of document.ready function

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 alert(startDate);
 });
 function getDateField(field)
 {
 var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
 var d = new Date(date);
 var month =d.getMonth() + 1; //adding 1 as January starts at 0
 var day =d.getDate();
 var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
 var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

To retrieve date and time in display form, use the below code:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
var start = $.trim($('h3:contains("Start Date")').closest('td').next('td').text());
alert(start);
});
</script>

Comparing Current Date and time with Date in DateTime field:

After retrieving the value from Date and Time field, let’s say we need to check the current date and time and hide if current date is greater than Start Date field.

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 var current=new Date();
 if(current>=startDate)
 {
 //hide fields
 }
 });
 function getDateField(field)
 {
var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
var d = new Date(date);
var month =d.getMonth() + 1; //adding 1 as January starts at 0
var day =d.getDate();
var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

To compare two SharePoint date fields, we need to call getDateField function for both the dates as:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
var startDate=getDateField("Start Date");//Display name of Date and Time field
var EndDate=getDateField("End Date");
 if(EndDate<=startDate)
 {
 alert("End Date should be greater than Start Date)
 }
 });
</script>

Hiding fields before three hours of start date in SharePoint

To hide the fields from three hours prior to start Date  time, lets subtract three hours from Start Date time and then compare with current date and time as shown below:

<script src="../Scripts/jquery.min.js"></script>
<script type="text/javascript"> 
$(document).ready(function()
 {
 var startDate=getDateField("Start Date");//Display name of Date and Time field
 var current=new Date();
 var subbed = new Date(startDate - 3*60*60*1000); // subtract 3 hours
 if(current>=subbed)
 {
 //hide fields
 }
});
function getDateField(field)
 {
var date = $(":input[title='" +field+ "']").val(); //retrieves date from date text box which is in mm/dd/yyyy format
var d = new Date(date);
var month =d.getMonth() + 1; //adding 1 as January starts at 0
var day =d.getDate();
var year = d.getFullYear();
//appending 0 for single digit date ad month
 if (month.length < 2) month = '0' + month; 
if (day.length < 2) day = '0' + day;
var dateID = $(":input[title='"+field+"']").attr("id");
var dateHours = $(":input[id='"+ dateID + "Hours" +"']").val();
var Meri=dateHours.split(' ')[1];
dateHours = dateHours.split(' ')[0];
//converting it into 24 hour format
 if(Meri == "PM" && dateHours<12)
    dateHours = parseInt(dateHours)+12;
 else if(Meri == "AM" && dateHours==12)
   dateHours = parseInt(dateHours)-12;
var dateMinutes=$(":input[id='"+dateID+"Minutes"+"']").val();
var requiredDate=new Date(year,month-1,day,dateHours,dateMinutes,0);
 return requiredDate;
 }
</script>

Please do not forget to like or rate the article 😛

 

 

Challenges faced after exporting Excel data to SharePoint


In previous article, we have seen how to connect to SharePoint site from excel for exporting data. Today, let us see the challenges faced in SharePoint after exporting the data.

  1. Number columns with greater than or equal to 4 digits in excel – Lets consider, Application ID column with value 20158 for better understanding. As number column in excel are associated with number column in SharePoint, they are displayed with commas as 20,158
    • To remove the commas, never try converting it into Single line of text in SharePoint because it will be converted into exponential form as 20+158e
    • If you would like to show them without commas, create a calculated column with the below formula:
    • =TEXT([Application ID], “0”)
    • By using this formula, Commas will be removed but calculated columns will be shown only in display form
    • So, before exporting it is recommended to convert number field with more than 4 digits in excel to text column as to associate it with single line of text. Now, to prevent the users from entering number in Single line of text field, follow the below steps:
    • Go to List->List settings and click on Application ID column
    • It takes us to Change Column page for Application ID where we need to enter the below formula in Data validation section and click ok
    • =ISNUMBER([Application ID]+0)
  2. Person or Group column in SharePoint for user names like Manager in excelAs text columns are associated with  Single line of text, they cannot be converted to Person or group column. What if we need to use People Picker(Person or Group) for user names. Below is a small workaround which will be useful if there are thousands of items.
    •  If number of items is less, create a person or group column, open edit form of each item and copy paste the value manually from single line of text to Person or group field. When there are large number of items(say 2000), create below two columns in SharePoint:
    • Flag – Yes/No type
    • Mgr – Person or group type in SharePoint
    • Go to SharePoint designer and create a workflow which should run whenever an item is changed
    • Create the below step:
      • If flag equals Yes
      • set Mgr(Person or group column) to Manager(Single line of text)
    • Now, go to Datasheet view of the list and simply select Yes and drag the Yes value till the last item
    • Advantage: It reduces the time than doing it manually
    • Disadvantages:
      • Workflow fails when exact match is not found meaning either the person has left the organization or their Id in active directory is changed
      • We need to manually fill for those items where workflow has failed
      • Remove the workflow from the list once all the user names are copied to Person or group column
  3. Missing “Add new item” link in SharePoint 2010 – To overcome this, create a Standard view and set it as default view

If the above post is helpful, do not forget to like my article and rate it.