Friday, January 4, 2019

Get Folders under Subfolder

 public string sMenuString = "";
        [HttpGet]
        [Route("api/GetFolderTreeView")]
        public string GetFolderTreeView()
        {
            string sharePointUrl = ConfigurationManager.AppSettings["SharePointURL"];
            string _spUserName = ConfigurationManager.AppSettings["userName"];
            string _spPwd = ConfigurationManager.AppSettings["Password"];
            try
            {
                using (ClientContext clientContext = new ClientContext(sharePointUrl))
                {
                    var passWord = new SecureString();
                    foreach (char c in _spPwd.ToCharArray()) passWord.AppendChar(c);
                    clientContext.Credentials = new SharePointOnlineCredentials(_spUserName, passWord);
                    Web web = clientContext.Web;
                    // We want to retrieve the web's properties.
                    clientContext.Load(web);
                    clientContext.Load(web.Lists);
                    clientContext.Load(web, wb => wb.ServerRelativeUrl);
                    clientContext.ExecuteQuery();

                    List list = web.Lists.GetByTitle("SampleDocuments");
                    clientContext.Load(list);
                    clientContext.ExecuteQuery();

                    Microsoft.SharePoint.Client.Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/SampleDocuments/0019E00000hQCs4QAG");
                    clientContext.Load(folder);
                    clientContext.ExecuteQuery();

                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
                                     <Query>
                                     </Query>
                                 </View>";
                    camlQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
                    ListItemCollection listItems = list.GetItems(camlQuery);
                    clientContext.Load(listItems);
                    clientContext.ExecuteQuery();

                    clientContext.Load(list.RootFolder);
                    clientContext.Load(list.RootFolder.Folders);
                    clientContext.ExecuteQuery();

                    foreach (var item in listItems)
                    {
                        if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                        {
                            // This is a  Folder
                            clientContext.Load(item.Folder);
                            clientContext.ExecuteQuery();
                            sMenuString += "Folder" + item.Folder.Name;

                        }
                        else if (item.FileSystemObjectType == FileSystemObjectType.File)
                        {
                            // This is a File
                            clientContext.Load(item.File);
                            clientContext.ExecuteQuery();
                            //sMenuString += "File : "+item.File.Name;
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                var errmsg = ex.Message;
            }

            return sMenuString;
        }
           

Friday, September 28, 2018

Using JSLink as an alternative for Calculated columns to Display Images Depending on Checkbox values

alert("Hello");

(function () {
    alert('starting')
    var fieldCtx = {};

    fieldCtx.Templates = {};
    fieldCtx.Templates.Fields = {
        "ShowOnDisplayBoard": //This is field name, make sure to enter the internal column name
        {
            "View": UpdateApprovalTempalte //Enter the function name
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldCtx);
})();

var imgTrue = "<img src='/siteassets/checked.png' width='16px'/>"
var imgFalse = "<img src='/siteassets/uncheck.png' width='16px'/>"
 

function UpdateApprovalTempalte(ctx) {
    var columnValue = ctx.CurrentItem.ShowOnDisplayBoard;  // get the value of the ApprovalColumn field of the current item
    var returnValue = "";
    if (columnValue == 'Yes')
        returnValue = imgTrue;
    else if (columnValue == 'No')
        returnValue = imgFalse;
    else if (columnValue == '')
        returnValue = imgFalse;
    else
        returnValue = columnValue;

    return returnValue;
}

Thursday, August 2, 2018

Backup and restore SharePoint online site

To back up and restore data in SharePoint Online, we can create an Office 365 support ticket to achieve it.
More information:
Thanks
Best Regards


I hope the above suggestion clarifies your concern, In SharePoint Online, we cannot backup and restore contents as what we do in SharePoint Server 2013. Instead, the backup and restoring features are reflected by the following features: version, template, recycle bin and some third party solutions.

Please follow this links to get more information about backup process in SharePoint Online

https://itsolutionsblog.net/the-backup-options-in-sharepoint-online/

How to back-up a Office 365 SharePoint Online site and data

Restore options in SharePoint Online
Hope this helps!


Migration solution to migrate to-and-from SharePoint and Office 365 along with File Servers, Exchange/Office 365 Public Folders, Google Drive and OneDrive Business to SharePoint Online/On-premise migration.

Friday, July 27, 2018

WebApi - Enable to CORS - cross domain - get Json format

WebApiConfig.cs under App_Start

using System.Net.Http.Headers;
using System.Web.Http;
using System.Web.Http.Cors; 


// Web API configuration and services
            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);


config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

//This will get JSOn format
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

List View Filter - Show only Today's Or Less than 7days items


If you want to filter only items that are less than 7 days old then you just use
Filter
  • Created
  • is greater than or equal to
  • [Today]-7
Note - the screenshot is incorrect.
New items - created in last 7 days


Tuesday, November 21, 2017

REST Query



Author/Title&$expand=Author/Id


https://mydomain.sharepoint.com/mysite/_api/web/lists/GetByTitle('MyList')/items?$filter=Column1 eq 1 AND Column2 eq 2 AND Column3 eq 3

SharePoint Crawl Errors and Resolution

ERROR No. 01
Failed to retrieve data from the External System: 'MethodInstance with Name 'AttachmentStream' on Entity (External Content Type) with Name 'SFDCArticle_CEntity' in Namespace '.BCS.Connector.SFDCArticle_C' failed unexpectedly. The failure occurred in method 'GetAttachments' defined in class 'SFDCArticle_CService' with the message 'Sequence contains no elements'.

Solution:-

When you get the LINQ Error "Sequence contains no elements", this is usually because you are using the First() or Single() command rather than FirstOrDefault() and SingleOrDefault().
https://stackoverflow.com/questions/1324199/sequence-contains-no-elements

ERROR No. 02
Failed to retrieve data from the External System: 'MethodInstance with Name 'ReadItem' on Entity (External Content Type) with Name 'SFDCArticle_CEntity' in Namespace '.BCS.Connector.SFDCArticle_C' failed unexpectedly. The failure occurred in method 'ReadItem' defined in class '.BCS.Connector.SFDCArticle_C.SFDCArticle_CService' with the message 'Object reference not set to an instance of an object.'.'

Solution:-
Empty File OR Recrawl

ERROR No. 03


Tuesday, October 24, 2017

How to create managed property using powershell in sharepoint admin

$searchapp = Get-SPEnterpriseSearchServiceApplication -Identity c7276513-625d-4921-a2df-09c02c6007e2
$category = Get-SPEnterpriseSearchMetadataCategory –Identity SharePoint -SearchApplication $searchapp
$crawledproperty = New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType 0 -PropSet "00130329-0000-0130-c000-000000131346" -Name "FAST_DBFIND_CCR.FAMILY_ID" -IsNameEnum $false
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name "FAMILYID" -Type 3 -FullTextQueriable $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name ACCOUNTNAME -Type 1 -FullTextQueri
able $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
New-SPEnterpriseSearchMetadataManagedProperty : A managed property of the same
name ("ACCOUNTNAME") already exists.
At line:1 char:20
+ $managedproperty = New-SPEnterpriseSearchMetadataManagedProperty
-SearchApplicat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidData: (Microsoft.Offic...ManagedProperty:
   NewSearchMetadataManagedProperty) [New-SPEnterpris...ManagedProperty], Inv
  alidNameException
    + FullyQualifiedErrorId : Microsoft.Office.Server.Search.Cmdlet.NewSearchM
   etadataManagedProperty

PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty

New-SPEnterpriseSearchMetadataMapping : Cannot bind argument to parameter
'ManagedProperty' because it is null.
At line:1 char:86
+ ... anagedProperty $managedproperty -CrawledProperty $crawledproperty
+                    ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpriseSearchMetadata
   Mapping], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.Office.Server.Search.Cmdlet.NewSearchMetadataMapping

PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "COMPANYNAME" -Type 1 -FullTextQue
riable $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1002



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "CREATEDATE" -Type 1 -FullTextQuer
iable $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1003



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "DBID" -Type 3 -FullTextQueriable
$true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1004



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "DOCENGINEER" -Type 3 -FullTextQue
riable $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1005



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "ENGINEER" -Type 3 -FullTextQueria
ble $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1006



PS C:\Users\SPDevServer> $managedproperty = New-SPEnterpriseSearchMetadataManage
dProperty -SearchApplication $searchapp -Name "FAMILYID" -Type 3 -FullTextQueria
ble $true -Queryable $true -Retrievable $true -SafeForAnonymous $true
PS C:\Users\SPDevServer> New-SPEnterpriseSearchMetadataMapping -SearchApplicatio
n $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty



CrawledPropset             : 00130329-0000-0130-c000-000000131346
CrawledPropertyName        : FAST_DBFIND_CCR.ACCOUNTNAME
CrawledPropertyVariantType : 0
ManagedPid                 : 1007



PS C:\Users\SPDevServer>

How to Deploy Your HTML Website on a Linux Server (Apache + SFTP)

Launching a simple HTML website on your own Linux server is easier than you might think. Whether you're sharing a static landing page or...