Tuesday, 28 February 2017

Generating PDF using ITextSharp dll in sandbox solution

Recently I got one requirement where I need to create PDF file and upload it as an attachment to list item from a Sandbox solution

Normally we can create PDF file using ITextSharp dll without any issue in Farm solution.

But in sandbox solution, this solution gave below errors
  1.  Assembly could not load error as we are adding external dll to sandbox
  2.  System.Security.SecurityException: exception because ITextSharp assembly does not allow partially trusted callers 
So first we need to update the dll to allow partial trust calls and then should add it to solution package

Make ITextSharp dll partial trust:

  1.   Download ITextSharp solution  Download iTextSharp
  2.  Open AssemblyInfo.cs of ‘ITextsharp-src-core’ project
  3.  Add below line in AssemblyInfo.cs
           [assembly: System.Security.AllowPartiallyTrustedCallers]
 Recompile solution and take latest itextsharp dll

Now add this dll to sandbox solution bin folder and add it in project references

Add dll to Solution package

Next step is to use the package configuration in order to deploy this assembly to Sandbox GAC cache. All 3rd party assemblies should be configured in sandbox solution package

1.     Open solution package and add dll from bin folder


Rebuild and deploy the sandbox solution. 

Now you can use ITextSharp methods to create PDFs




Monday, 10 August 2015

Powershell - Formatting output of powershell

While running powershell commands, sometimes output is displayed partially with '...'.


In order to display the output fully, use ft -AutoSize as below

get-service | ft -AutoSize


But if the length of string is too big, even ft -Autosize results output with '...'. To fix it, use below width parameter of out-string 
get-service | ft -AutoSize | Out-String -Width 4096



Saturday, 11 October 2014

How to install new feature through update solution

Normally, update solution will not install any new features that are added in the WSP
Run the normal Update solution command and use below PS to install feature

Install-SPFeature -path "New Feature Name"