Tuesday 20 December 2016

Client Object Model code to find List item level permissions



Client Object Model Code to find list items that has unique permissions



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;


namespace CSOMTestUserAccessItems
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext ctx = new ClientContext("http://spdev.sp2013.com/");
            ctx.AuthenticationMode = ClientAuthenticationMode.Default;
            ctx.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            Web web = ctx.Web;
            ctx.Load(web, w => w.Title);
            ctx.Load(web, w => w.CurrentUser.LoginName);
            List list = ctx.Web.Lists.GetByTitle("Products");
            CamlQuery qry = new CamlQuery();
            qry.ViewXml = "<view></view>";
            ListItemCollection Listitems = list.GetItems(qry);
            ctx.Load(Listitems);
            ctx.Load(Listitems, li => li.Include(i => i.HasUniqueRoleAssignments));
            ctx.ExecuteQuery();
            var user = web.CurrentUser.LoginName;
            foreach (ListItem item in Listitems)
            {
                Console.WriteLine();
                if ((item.HasUniqueRoleAssignments))
                {

                    ClientResult<BasePermissions> permissions = item.GetUserEffectivePermissions(@"i:0#.w|sp2013\manjunath.soreddy");
                    ctx.ExecuteQuery();
                    var hasPermissions = permissions.Value.Has(PermissionKind.ViewListItems);
                    if (hasPermissions)
                    {
                        Console.WriteLine(item["Title"] + " ...." + item["Price"] + "....." + item["Quantity"]);
                    }
                }


            }
            Console.Read();
        }
    }

}

Thursday 18 August 2016

Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully


Restore-SPSite -Identity "http://softwaredev.sp2013.com/" -Force  -Path "E:\BACKUP\gcs-Prodsitecoll-07132016.bak" -Confirm:$false 


Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully.  No content  databases in the web application were available to store your site collection.  The existing content databases may  have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain  a copy of this site collection.  


Solution : 


specify the parameters DatabaseServer and DatabaseName details which will fix the issue

Restore-SPSite -Identity "http://softwaredev.sp2013.com/" -Force  -Path "E:\BACKUP\gcs-Prodsitecoll-07132016.bak" -Confirm:$false  -DatabaseServer "inblrinvapp02dp" -DatabaseName "WSS_Content_softwaresupportdev"





Monday 18 July 2016

AddAttachment CSOM SharePoint 2010

AddAttachment to Sharepoint 2010 List item CSOM


Below is the code  to add an attachment to sharePoint 2010 list item through CSOM with WebReference, 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.IO;
using System.Data;
using System.Net;

namespace CSOMFileUpload
{
    class Program
    {
        static void Main(string[] args)
        {
           
            const string listName = "Test";                   
            var credentials = new NetworkCredential("manjunath.soreddy", "MS", "dev");
            var clientContext = new ClientContext("https://spdev.com/TestSite/");
            clientContext.Credentials = credentials;
            var list = clientContext.Web.Lists.GetByTitle(listName);
            var itemCreateInfo = new ListItemCreationInformation();
            var newItem = list.AddItem(itemCreateInfo);
            newItem["Title"] = "Soreddy Client API";
            newItem.Update();
            clientContext.ExecuteQuery();
            clientContext.Load(newItem);
            clientContext.ExecuteQuery();          
            string path = @"c:\OutPutLog.txt";
           
//Here Uploadfile.inv is a Webreference which we have added to SharePoint 2010 Site from Visual Studio to add follow below steps
// Solution Explorer---> Add Service Reference ---> Advanced-> Add Web Reference --> URL

           var refin = new Uploadfile.inv.Lists();
           refin.Credentials = CredentialCache.DefaultCredentials;
           refin.Url = "https://spdev.com/TestSite/");
/_vti_bin/Lists.asmx";
           refin.AddAttachment(listName, newItem["ID"].ToString(), Path.GetFileName(path),
                                      System.IO.File.ReadAllBytes(path));
        }
    }
}



OutPut:





Load All UserProfile properties CSOM


Load All the UserProfile properties of a Logged in User 



Below code will load all user profile properties of a current logged in user in CSOM


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
using System.Net;


namespace UserProfilePropertiesCSOM
{
    class Program
    {
        static void Main(string[] args)
        {

            ClientContext ctx = new ClientContext("http://Sharepointdevsite:3636/");
            var cuser = ctx.Web.CurrentUser;
            ctx.Load(cuser); //Load the Current Logged User
            ctx.ExecuteQuery();       
            PeopleManager peopleManager = new PeopleManager(ctx);        
            PersonProperties userProperites = peopleManager.GetPropertiesFor(cuser.LoginName);
            ctx.Load(userProperites, p => p.AccountName, p =>
            p.UserProfileProperties);
            ctx.ExecuteQuery();
            foreach (var property in userProperites.UserProfileProperties)
            {
                Console.WriteLine(string.Format("{0}: {1}",
                property.Key.ToString(), property.Value.ToString()));
            }
            Console.ReadKey(false);

        }
    }
}

Ouput:





Monday 4 July 2016

Unknown SharePoint version: 16.0 Parameter name: version 0 0

Error while deploying app to SharePoint 2013 from Visual Studio



Solution :


Go to Project -> Project Properties from Visual Studio

 i.e In the Tools menu

Debub -> yourprojectName Properties  ( In mycase its TestApp Properties)














In SharePoint Tab -> Change the Version from SharePoint online to SharePoint 2013 and Click OK

Try to Rebuild and deploy the solution hope it should fix




Tuesday 7 June 2016

Message from External System Login Failed for user ....


Message from External System Login Failed for user ....


When we are trying to create an External Content type with SharePoint Designer we will face an issue some thing like Message from External System Login Failed for user ... In order to fix it follow the below steps,.




Solution :

Click on Add Connection - > Select  second option Connect with impersonated Windows Identity

and provide Secure Store Application Id which was created in Central Admin to connect external system and Click on Ok button


select the option as per your requirment by Right clicking on Students table




Access denied by Business Data Connectivity.


Access denied by business data connectivity when creating external content type



Solution :


Go to Central Administration -> Manage Service Applications -> Business Connectivity Service application



Select the External Content type which you have created, and click on Set Object Permissions button in the ribbon,

In my case its NewExternal content type.



Type EveryOne and click on Add button and Select Execute Check box and Click on OK Button




That's set..., you will be able to see the result , if still getting same error select Edit checkbox and try it.






Tuesday 31 May 2016

The Secure Store Service application Secure Store Service Application is not accessible. The full exception text is:

Secure Store Service is not accessible

The Secure Store Service application Secure Store Service Application is not accessible. The full exception text is: The HTTP service located at https://........./SecureStoreService.svc/https is unavailable.  This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.













Resolution:

1. Check AppPool Account which secure store service is running is not stopped.

Go to Inetmgr -> Find the application pool for Secure store Service  





If Stopped - start the AppPool



2.  Check if Secure store service is not started,  if not go and Start as below.

Central Admin - > Application Management -> Manage Services on the Server 

Secure Store Service -> Start


Hope this will fix the issue , 

A Network-related or instance-specific error occurred while establishing connection to SQL Server,

A Network-related or instance-specific error occurred while establishing connection to SQL Server, The Server was not found or was not accessible. verify that instance name is correct and that SQL Server is configured to allow remote connections.





Solution :




Monday 30 May 2016

Verification of prerequisites for Domain Controller promotion failed. The local Administrator account becomes the domain Administrator account when you create a new domain. The new domain cannot be created because the local Administrator account password does not meet requirements. Currently, a password is not required for the local Administrator account. We recommend that you use the net user command-line tool with the /passwordreq:yes option to require a password for this account before you create the new domain; otherwise, a password will not be required for the domain Administrator account.

Error While Setting Active Directory:


Verification of prerequisites for Domain Controller promotion failed. The local Administrator account becomes the domain Administrator account when you create a new domain. The new domain cannot be created because the local Administrator account password does not meet requirements. Currently, a password is not required for the local Administrator account. 

We recommend that you use the net user command-line tool with the /passwordreq:yes option to require a password for this account before you create the new domain; otherwise, a password will not be required for the domain Administrator account.


Resolution:








Change SQL Server Authentication Mode


  1. In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
  2. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
  3. In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.
  4. In Object Explorer, right-click your server, and then click Restart. If SQL Server Agent is running, it must also be restarted.
 Change Security Authentication Mode



Enabling login for sa account

  1. In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties.
  2. On the General page, you might have to create and confirm a password for the login.

On the Status page, in the Login section, click Enabled, and then click OK.





Sunday 14 February 2016

Create Publishing Page using Powershell/ Create Pages from csv file



Below is the code which will create the Publishing page and added to Pages library . Here i am using Blankwebpart page layout and reading pageurls from text file and creating pages.

cls
asnp "*sh*"
$web=Get-SPWeb -Identity http://SP2013dev:3636/
$pubweb=[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$file=Import-Csv -LiteralPath E:\MS\temp\pageurls.txt
$pageLayout=$pubweb.GetAvailablePageLayouts()|?{$_.Name -eq "BlankWebPartPage.aspx"}
foreach($page in $file.PageUrls)
{
$newPage=$pubweb.AddPublishingPage($page,$pageLayout);
$newPage.Update();
$newPage.CheckIn("Creating new page");
$newPage.ListItem.File.Publish("new page is created");
$web.Dispose();

Write-Host $page "Page is created" -ForegroundColor Green




text file(pageurls.txt):

PageUrls,
ISSAboutUs.aspx
ISSContactUs.aspx
ISSCustomerFirst.aspx
ISSVideos.aspx
ISSGenericCF.aspx
SolutionHub.aspx
ISSTechnotes.aspx



OutPut




Monday 4 January 2016

Error while Configuring App Urls

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings. 




Solution:

Central Administration -> Application Management -> Service Applications -> Services on the Server


Click Start button of  

App Management Service and Microsoft SharePoint Foundation Subscription Settings Service 


























If you are still facing same issue then do an IISReset which will fix the issue.



Alternative We can RunPowerShell Scirpt to fix the issue if You haven't configured Service applications for AppManagement and Subscirption Service Settings 



cls
asnp "*sh*"


Get-SPServiceInstance |?{$_.TypeName -like  "App Management Service"| Start-SPServiceInstance

Get-SPServiceInstance | ? {$_.TypeName -like "Microsoft SharePoint Foundation Subscription Settings Service"| Start-SPServiceInstance

#Provide the service account as per your configuration 

$account=Get-SPManagedAccount -Identity CORP\Svc.AppsAccount

#configure Subscription Service Application for Sharepoint

$appPoolSubsvc=New-SPServiceApplicationPool -Name "SubscriptionServericeAppPool" -Account $account
$appSubSvc=New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubsvc -Name "Subscription Service Application" -DatabaseName SubscriptonServiceDB
$proxySubSvc=New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $appSubSvc
Write-Host "Subscirption Service Application Created"


$appPoolAppSvc= New-SPServiceApplicationPool -Name "AppManagementServiceAppPook" -Account $account
$appsMgmtSvc= New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name "Apps Management Service" -DatabaseName "AppsDb"
$proxyAppSvc=New-SPAppManagementServiceApplicationProxy -ServiceApplication $appsMgmtSvc

Write-Host "Apps Management Service Application Created"