Thursday, January 22, 2015

Understanding the Global Assembly Cache (GAC) and Managing , Copying Dlls from Global Assembly Cache

Most of you may confuse why there are two GACs available in the machine.

  • C:\WINDOWS\assembly
  • C:\WINDOWS\Microsoft.NET\assembly

What is GAC

GAC is a shared location in your machine that keeps assemblies, Dlls for common sharing purpose. Assume that you are using system.data.dll in your project. so one option is you can place the dll with your project. but assume you are creating another project which is also using the same .net assembly system.data.dll. so it is better to have it in a common place which that can be referred.

since it is a common framework dll and used separately from your application logic it is good to place in a shared place for easy of maintenance and update process.

What is  C:\WINDOWS\assemblyimage

Previous CLRs uses this place as its common location for Dlls. previous CRLs includes versions 1.0,1.1,2.0. these CRLs versions are used by before .NET framework 4.

.NET Framework 1.0  - CLR v1.0
.NET Framework 1.1  - CLR v1.1
.NET Framework 2.0  - CLR v2.0
.NET Framework 3.0  - CLR v2.0
.NET Framework 3.5  - CLR v2.0

so if you are working with application belongs to these versions; this is the place for your global assembly cache.

What is  C:\WINDOWS\Microsoft.NET\assembly

After CLR version 4.0 Microsoft change their location to this for maintaining and avoid loading wrong Dlls in applications for backward compatibility.

.NET Framework 4.0  - CLR v4.0
.NET Framework 4.5  - CLR v4.0
.NET Framework 4.5.1  CLR v4.0
.NET Framework 4.5.2  CLR v4.0

so if you are engaging with application after .NET Framework 4.0; this is the default location for it’s assemblies.

Managing and Copying Dlls from Global Assembly Cache

  • shfusion.dll
  • Gacutil.exe

shfusion.dll

this is a windows shell extension which shifts before framework 4.0 to manage Dlls in GAC.

if you navigate to  C:\WINDOWS\assembly from your file explorer you can see something like this that you can not manipulate.

image

so you can use following command to make it manipulate.

  • Goto command prompt (cmd) and open it as run as Administrator
  • then run the command
C:\Windows\system32>regsvr32 /u  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll

 


image


When you click enter it will prompt with a message like below which turn your GAC into manageable state.


image
if you navigate to C:\WINDOWS\assembly ; you can see it by your self.


image


You can revert it back to normal by registering the dll again

C:\Windows\system32>regsvr32 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll

shfusion.dll is only available till framework 4.0 and its versions. Now it is discontinued and not shipping with the framework. if you are having multiple versions installed use the latest framework folder.


EX:- Microsoft.NET\Framework\<.NET version> \shfusion.dll


Gacutil.exe


This the alternative if you are dealing with Dlls after  4.0 you need to use the gacutil.exe. you can type gacutil in visual studio command prompt and get list of command available for dll manipulating.


image

Friday, January 16, 2015

How to open Documents in Office Web Apps in SharePoint apps (Provider Hosted and SharePoint Hosted)

Office web apps are now getting more and more popular with the SharePoint 2013 environment. In native SharePoint environment when you click on a document it will open in a office online (OWA) based on configuration.

But it you a writing a SharePoint Hosted app or a Provider Hosted app; you might wonder how to open it in office web apps and what is the URL you are going to use it.

You can use JSOM and SharePoint REST services to archive this.

Frist you need to send a REST request by mentioning file name.

url: AppWebUrlUrl + "/_api/web/GetFileByServerRelativeUrl('server relative file name')",
method: "GET",
contentType: "application/json;odata=verbose",
headers: { "Accept": "application/json; odata=verbose" }

You should carefully give the sever relative file name for this operation. regardless of app type (Provider hosted or a SharePoint Hosted ) file name it coming with app web url


Ex:


Absolute File Url


https://oapp-bfb82901075d6b.sharepoint.com/sites/dev/myapp/lists/lcrdocs/file1.doc


Relative File Url


/sites/dev/myapp/lists/lcrdocs/file1.doc


Depending on the App type either you need to use the RequestExecutor or normal rest approach.


Using RequestExecutor in Provider Hosted Apps



var executor = new SP.RequestExecutor("app web url"); // you need to pass app web url
 
executor.executeAsync({
url: "app web url" + "/_api/web/GetFileByServerRelativeUrl('relative doc url')",
method: "GET",
contentType: "application/json;odata=verbose",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
    var arry = JSON.parse(data.body).d;
    if (arry.LinkingUrl) {
        // can open with office web apps
        var owaurl = "app web url" + "/_layouts/15/WopiFrame.aspx?sourcedoc={" + arry.UniqueId + "}&file=" + encodeURIComponent(arry.Title) + "&action=default";                   
    } else {
        // can not open with office web apps (ex:txt)
    }
},
error: function (data, errorCode, errorMessage) {
// error
}
});

if the LinkingUrl available it indicates it can be open via office web apps. LinkingUrl some times returns direct web app url ; thus you don’t need to create the Url by amending items but some times it returns absolute document Url. mentioned approach will be suits for both occasions.  


Ajax Request in SharePoint Hosted Apps



$.Ajax({ // Jquery needed
url: "app web url" + "/_api/web/GetFileByServerRelativeUrl('relative doc url')",
method: "GET",
contentType: "application/json;odata=verbose",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
    var arry = JSON.parse(data.body).d;
    if (arry.LinkingUrl) {
        // can open with office web apps
        var owaurl = "app web url" + "/_layouts/15/WopiFrame.aspx?sourcedoc={" + arry.UniqueId + "}&file=" + encodeURIComponent(arry.Title) + "&action=default";                   
    } else {
        // can not open with office web apps (ex:txt)
    }
},
error: function (data, errorCode, errorMessage) {
// error
}
});

Monday, January 12, 2015

Information Rights Management in Office 365 (IRM SharePoint Online)

 

Office 365 recently comes with a IRM feature that you can control the rights of  a document library and a List.

Current IRM supports only Restrict permissions on this library on download but this option contains other few options that I will explain later.

SharePoint online currently supports below documents types. This may change in new releases.

  • PDF
  • Word, Excel, and PowerPoint (97-2003 versions)
  • The XML Paper Specification (XPS) format 

Ref: https://support.office.com/en-us/article/Set-up-Information-Rights-Management-239ce6eb-4e81-42db-bf86-a01362fed65c

How to Configure Information Rights Management in Office 365

Step One (Activate Information Rights Management in o365 )

First you need to activate the Rights Management from service settings.

image

  • Then click on Manage and click activate for enable.
  • Then you will see the activation on the page.

image

Step Two (Activate Information Rights Management in SharePoint )

  • Now you activate the SharePoint Rights Management
  • Go to SharePoint Admin page

image

  • Go to Settings section and Use the IRM service selection option.

image

Step Three (Configure Rights Management in Document Library)

  • Go to your SharePoint Site and Library/List and go to Settings
    • Click on the  Information Right Management

image

    • Check the Restrict permissions on this library on download and Enter Name and Description for the IRM Policy. here you can click SHOW OPTIONS for other configurations.

image

Options include

  • Do not allow users to upload documents that do not support IRM
  • Stop restricting access to the library at specific date
  • Prevent opening documents in the browser for this Document Library
  • Allow viewers to print
  • Allow viewers to run script and screen reader to function on downloaded documents
  • Allow viewers to write on a copy of the downloaded document
  • After download, document access rights will expire after these number of days (1-365)
  • Users must verify their credentials using this interval (days)
  • Allow group protection

Tuesday, December 16, 2014

Your account is configured to prevent you from using this computer. Please try another computer

I have got this message when I tried to access a remote machine which is in domain. I’m having all the privileges to this machine but still error got prompted.

This is actually not because of the permission but because of the active directory policy. You need to go to active directory and change the Log on To ..  

In here best thing is select All Computers option.If not add machine name to The following computers section (not the IP Address).

image