Thursday, January 7, 2021

Get file url from SharePoint by name

 List docs = web.Lists.GetByTitle("DOCUMENTS");

Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);

clientContext.ExecuteQuery();


clientContext.Load(uploadFile.ListItemAllFields, item => item["EncodedAbsUrl"]);

clientContext.ExecuteQuery();


var fileUrl = uploadFile.ListItemAllFields["EncodedAbsUrl"].ToString();


string link = ctx.Web.CreateAnonymousLinkForDocument(fileUrl, ExternalSharingDocumentOption.View);


string linkwithExpiration = ctx.Web.CreateAnonymousLinkWithExpirationForDocument(fileUrl, ExternalSharingDocumentOption.Edit, DateTime.Now.AddMonths(1));


SharingResult result = ctx.Web.ShareDocument(fileUrl, "reven@peakfinders.com", ExternalSharingDocumentOption.View, true, "Documents shared Sucessfully");


Wednesday, January 6, 2021

How to read site page contents in SharePoint using CSOM?

 var listTitle = "Site Pages";

var list = ctx.Web.Lists.GetByTitle(listTitle);

var items = list.GetItems(CamlQuery.CreateAllItemsQuery());

ctx.Load(items, icol => icol.Include( i => i["WikiField"], i => i["Roaf"], i => i["FileRef"], i => i.ContentType));

ctx.ExecuteQuery();

foreach (var item in items)

{

     Console.WriteLine(">>> {0}", item["FileRef"]);

     switch (item.ContentType.Name)

     {

        case "Site Page":

          Console.WriteLine(item["Roaf"]);

          break;

        case "Wiki Page":

          Console.WriteLine(item["WikiField"]);

          break;


     }    

 }

How to enable JSON response for SharePoint 2013 REST APIs ?

 headers: { "accept": "application/json", },


Instead using headers: { "accept": "application/json;odata=verbose", },

Could not load file or assembly SharePoint Online CSOM DLL

 https://www.microsoft.com/en-us/download/details.aspx?id=42038

Add-Type -Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

Add-Type -Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'   

Access denied in office 365 / SharePoint Online

  •  Login your Office 365 account.
  • Go to the SharePoint admin center.
  • Select Settings.
  • Under Custom Script choose:


  • Prevent users from running custom script on personal sites or Allow users to run custom script on personal sites.
  • Prevent users from running custom script on user created sites or Allow users to run custom script on self-service created sites.


var tenant = new Tenant(ctx);
    var SiteProp = tenant.GetSitePropertiesByUrl(http://devprasad007-admin.sharepoint.com, true);
    ctx.Load(SiteProp);
ctx.ExecuteQuery(); SiteProp.DenyAddAndCustomizePages = DenyAddAndCustomizePagesStatus.Disabled;
var result = SiteProp.Update();
ctx.Load(result); ctx.ExecuteQuery(); while (!result.IsComplete) { Thread.Sleep(result.PollingInterval); ctx.Load(result); ctx.ExecuteQuery(); 

    } 

Thursday, December 24, 2020

SharePoint: How to get Retrieve Publishing image field with SharePoint 2013 REST Api / CSOM

Below rest api code get publish feature fields 


function getPublishingPage(webUrl,listName,listItemId,publishingProperties, success, failure) 

{

    var itemUri =  webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")";  

    getJson(itemUri,

       function(data){

           var pageItem = data.d;


           var selectProperties = [];  

           for(var idx in publishingProperties){

               if(!pageItem.hasOwnProperty(publishingProperties[idx])){

                   selectProperties.push(publishingProperties[idx]);

               }

           }

           if(selectProperties.length > 0) {

              //construct an additional query 

              var query = '/FieldValuesAsHtml?$select=' + selectProperties.join(',');

              var endpointUri = pageItem['__metadata'].uri + query;

              getJson(endpointUri,

                 function(data){

                    for(var property in data.d){

                       if(property == "__metadata") continue; 

                       pageItem[property] = data.d[property];   

                    }

                    success(pageItem);  

                 },

                 failure);

           } 

           else {

              success(pageItem);

           }   

        },

       failure);

}

Unauthorized exception while downloading file from SharePoint

In this article, How to download the SharePoint  library files in Document Library


 var file = clientContext.Web.GetFileByServerRelativeUrl(fileRef);

                clientContext.Load(file);

                clientContext.ExecuteQuery();                    

                ClientResult<Stream> streamResult = file.OpenBinaryStream();

                clientContext.ExecuteQuery();

#sharepoint #SharePoint Developer/  #O365 #Administrator/ #NET #jQuery #AngularJS #poweapps #powerautomate #spfx #pnp #workflo

Thursday, December 17, 2020

Disable Delve in SharePoint Online?

 Login to your SharePoint Admin Center

Click on "Settings" from left navigation >> Click on "classic settings page" in the bottom>> Under Office graph, Select "Don't allow access to the Office Graph"


Click and Save the button

Monday, December 14, 2020

SharePoint Installation Error : Application Server Role ,Web Server Roll Configuration Error

 
SharePoint Installation Error : Application Server Role ,Web Server Roll Configuration Error

You have a couple of options here:

Enable .Net 3.5 on the server and retry the pre-requisite installation.
Manually add the required features using PowerShell.


The PowerShell to add the required features is:

Import-Module Servermanager

Add-WindowsFeature NET-HTTP-Activation,NET-Non-HTTP-Activ,NET-WCF-Pipe-Activation45,NET-WCF-HTTP-Activation45,Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-App-Dev,Web-Asp-Net,Web-Asp-Net45,Web-Net-Ext,Web-Net-Ext45,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Http-Tracing,Web-Security,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Digest-Auth,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Mgmt-Tools,Web-Mgmt-Console,Web-Mgmt-Compat,Web-Metabase,WAS,WAS-Process-Model,WAS-NET-Environment,WAS-Config-APIs,Web-Lgcy-Scripting,Windows-Identity-Foundation,Xps-Viewer -verbose

The PowerShell above adds all of the features that the pre-requisite installer adds.


Wednesday, December 9, 2020

Could not authenticate to SharePoint Online using OAuth 2.0

SharePoint Online using OAuth In this article ,

Could not authenticate to SharePoint Online using OAuth 2.0

 $username = "test@am.onmicrosoft.com"

$password = "******"


$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)


Connect-SPOService -Url https://finders-admin.sharepoint.com -Credential $cred