Search This Blog

Showing posts with label Office 365. Show all posts
Showing posts with label Office 365. Show all posts

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/

Saturday, June 10, 2017

Authenticating .NET Client Object Model in Office 365 using shareepoint online

The below code is used to authenticating sharepoint online site

using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))
{
    SecureString passWord = new SecureString();

    foreach (char c in "yourpassword".ToCharArray()) passWord.AppendChar(c);

    clientContext.Credentials = new SharePointOnlineCredentials("admin@yoursite.onmicrosoft.com", passWord);

    Web web = clientContext.Web;

    clientContext.Load(web);

    clientContext.ExecuteQuery();

    Console.WriteLine(web.Title);

    Console.ReadLine();
}

How to remove registered app from sharepoint online

In this post i will explain how to remove registered app from sharepoint online.

For this please install Azure PD Powershell before going through this post.

Open the  Installed  Azure PD Powershell with run as Administrator permission.and run the following sript to remove the app from sharepoint online.

Connect-MsolService
$appPrincipal = Get-MsolServicePrincipal -ServicePrincipalName 'Paste your app client id here'
Remove-MsolServicePrincipal -ObjectId $appPrincipal.ObjectId

After executing the above script please register your app again in 
"SiteUrl/_layouts/15/appregnew.aspx"






Sunday, December 11, 2016

Adding Remote Event Receivers To An Exisiting List In Office 365

// This Below method is used to build creation information for the event receiver.

public static EventReceiverDefinitionCreationInformation CreateGenericEventRecieverWithoutEventType()
{
string remoteAppurl = HttpContext.Current.Request["RemoteAppUrl"];
string remoteEventEndPointUrl = String.Format("{0}/ServiceName.svc", remoteAppurl);
EventReceiverDefinitionCreationInformation eventReceiver = new EventReceiverDefinitionCreationInformation();
eventReceiver.ReceiverName = "Give Your Receiver Name";
eventReceiver.ReceiverUrl = remoteEventEndPointUrl;
eventReceiver.SequenceNumber = 5000;
eventReceiver.ReceiverClass = "Fully qualified Path To RER Assembly";
eventReceiver.ReceiverAssembly = Assembly.GetExecutingAssembly().FullName;
return eventReceiver;
}

// The below method is used to check whether the event receiver is already exists in the lists or not

public static bool DoesEventReceiverDefintionExistBasedOnCreationInfo(EventReceiverDefinitionCreationInformation info, List list)
{
bool exists = false;
list.Context.Load(list, x => x.EventReceivers);
list.Context.ExecuteQuery();
foreach (EventReceiverDefinition eventReceiverDefinition in list.EventReceivers)
{
string innerDefId = eventReceiverDefinition.ReceiverClass;
string outerDefId = info.ReceiverClass;
if (innerDefId.Equals(outerDefId, StringComparison.InvariantCultureIgnoreCase))
{
exists = true;
break;
}
}
return exists;
}

// Since the receivers were built without a specific event type, you can specify as many receiver capture behaviors as you want, as demonstrated in the below example.

public static void AttachEventReceiver(ClientContext context, List list)
{
EventReceiverDefinitionCreationInformation eventReceiver =CreateGenericEventRecieverWithoutEventType();
eventReceiver.EventType = EventReceiverType.ItemAdded;
if (!DoesEventReceiverDefintionExistBasedOnCreationInfo(eventReceiver, list))
{
list.EventReceivers.Add(eventReceiver);
}
eventReceiver = CreateGenericEventRecieverWithoutEventType();
eventReceiver.EventType = EventReceiverType.ItemUpdated;
if (!DoesEventReceiverDefintionExistBasedOnCreationInfo(eventReceiver, list))
{
list.EventReceivers.Add(eventReceiver);
}
eventReceiver = CreateGenericEventRecieverWithoutEventType();
eventReceiver.EventType = EventReceiverType.ItemDeleted;
if (!DoesEventReceiverDefintionExistBasedOnCreationInfo(eventReceiver, list))
{
list.EventReceivers.Add(eventReceiver);
}
eventReceiver = CreateGenericEventRecieverWithoutEventType();
eventReceiver.EventType = EventReceiverType.ItemFileMoved;
if (!DoesEventReceiverDefintionExistBasedOnCreationInfo(eventReceiver, list))
{
list.EventReceivers.Add(eventReceiver);
}
context.ExecuteQuery();
}

//The below method is used to delete event receivers in the list 

public static void DeleteEventReceiver(ClientContext context, List list)
{
EventReceiverDefinitionCollection eventReceiverDefinitionCollection = list.EventReceivers;
context.Load(eventReceiverDefinitionCollection);
context.ExecuteQuery();
List<Guid> ids = eventReceiverDefinitionCollection.Select(eventReceiverDefinition => eventReceiverDefinition.ReceiverId).ToList();
foreach (EventReceiverDefinition definition in ids.Select(eventReceiverDefinitionCollection.GetById))
{
definition.DeleteObject();
context.ExecuteQuery();
}
}