Sharepoint On-premises script injection with Powershell


Inject custom JavaScript file to all pages



I want add script into site without editing master page. Using Javascript Injection we can easily add our custom script into all pages.
Below PowerShell script to inject custom file to all pages.

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$SiteURL = "http://dotnetsharepoint.com/sites/PublishingSite/"
 
$actionName = "Lakshmi_JS_INjection"
$actiontype = "ScriptLink"
#Custom Script File
$actionSourceFile ="http://dotnetsharepoint.com/sites/PublishingSite/Documents/Test%20Inject.js"

 $Context =New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$web = $Context.Web
$Context.Load($web)
$context.Load($web.Webs)

  $Context.ExecuteQuery()


 if($web)

 try

  {
#for all subsites
 foreach($web in $web.Webs)
{
  Write-Host 'Site collection:' $web.Url   


  Write-Host '-----------------------------'
$actions = $web.get_userCustomActions();
$Context.Load($actions)
$Context.ExecuteQuery()
if($actions)

{
#Delete existing script inject

 foreach($action in $actions)
{
if($action.get_description() -eq $actionName -and $action.get_location() -eq $actionType){
$action.deleteObject()

}

}

}
 $newAction = $actions.add();
$newAction.set_description($actionName);
$newAction.set_location('ScriptLink');
$scriptBlock = 'var headID = document.getElementsByTagName("head")[0];var newScript = document.createElement("script");newScript.type ="text/javascript";newScript.src ="';
$scriptBlock += $actionSourceFile + '?ver=' +(Get-Date);
$scriptBlock += '";headID.appendChild(newScript);';
$newAction.set_scriptBlock($scriptBlock);
$newAction.update();
$Context.ExecuteQuery();
Write-Host "Added"

}

}
 catch
  {
 Write-Host "error"

}

}   

how to create PDF Converter Advance Smart Object


PDF Converter

If we want to create PDF file without opening the form or view, we can use this PDF Converter.

Example: Html or URL

Using PDF Converter Smart Object we can create PDF file to send a mail.
For this First we have to create Advance Smart Object using existing PDF Converter Object.

Creating Advance Smart Object

Click on Crete New Smart Object on which list you need. Enter name , select Advance SmartObject  & Allow this to be used in workflow as shown in figure below.



Drag PDF converter to Property     
                                                                                                 

The PDF Converter has three functions:

  • Create PDF from HTML (raw HTML to PDF Format)
  • Create PDF from URL (Captures a URL to PDF Format)
  • Create PDF from HTML or URL

HTML - Creates a PDF file at a certain point in time
URL - Creates a PDF file upon load of the page
 
 It will open Add SmartObject window -> Go to Default ServiceObject method binding and Click on Create All



Click on finish , now we can see the Properties and & Method.
 



Click Finished. Now we created PDF Converter Advance SmartObject.
 

 Reference:
http://help.k2.com/onlinehelp/k2smartforms/userguide/1.0.4/webframe.html#pdf_converter_service_broker.html

Create Cascading drop-down list in k2 SmartForms

 

In this article i explain how to filter the drop down list based on State and City.

Create State and City list with lookup and create smartobject for this lists.

I have created view with State & City Dropdown




 Select the state dropdown -> click on type under DataSource in Properties


Configure Data Source with State Smart Object and Display value-> Click OK

Select the City dropdown -> click on type under DataSource in Properties ->Configure Data Source with State Smart Object ,Display value and Filter as shown in figure -> Click OK
Now goto "Rules" -> When DDLState is changed rule will generate automatically, Edit the rule.                      


Click on Configure. 
No need to map anything, it will automatically map the Filter value.                                                               


Click Ok and Finish the view. Now run the view and Check.


Hope it's help..:)

How to restrict users for creating views in SharePoint

In this article we can able to see how to restrict users to create views in SharePoint, User having contribute permissions but he can able to create views as per the below screen shot.
We can restrict user to create views by creating the custom permissions as shown below.
Navigate -> Site Settings ->Site Permissions

In the top ribbon we are able to see Permission levels.


Click on the Permission levels, we can able to see the contribute permission level, in the down we can able to see the “Copy Permission level

Click on the “Copy Permission level”, create a Name “Contribute_NoViews

In down remove the options for “Manage Personal views” and click on submit.
Assign the permission level to the particular group, now we cannot find option to create views.

Web Application is prompting for Username and Password Credentials in SharePoint 2013




An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

  • Go to Run -> REGEDIT  - > HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Control -> Lsa -> MSV1_0


  • Right Click on MSV1_0 -> New -> Multi-String value


  • Name it has ‘BackConnectionHostNames’. Now Right click & Select ‘Modify’
  • Enter the Hostname of the site.
  • Click Ok.
  • Now Restart IIS & Restart machine.