Download Files from Media Library using Sitecore PowerShell Extension

SPE is a powerful tool. You can do a lot with it. So, whenever I think something needs a lot of manual intervention and can be automated I look into SPE.

So, here I am, trying to download a bunch of files from one Sitecore instance and bring it over for reorganization, renaming and reused.

SPW, has GET-ITEM and SEND-ITEM. So I jump in.

Get-Item -Path "master:" -Query "/sitecore/media library/Images/Habitat/" | Send-File -NoDialog

But, it was only downloading one file. What the cinnamon toast crunch am I missing?

So, I went deeper and dumber and used a script that does Get-Item on the root, Foreach thru all the items, then run Send-File one at a time. No Dice. It only ran once then Sitecore hung.

After a bunch of trials and errors I ditched “-NoDialog” and a heavenly dialog showed up.

Clicked on Download, It downloaded the file. Clicked on Close and another dialog showed up for the next file. And then do this for 346 more time. I think not.

MichaellWest jumped in saying “I believe I have seen that issue before. Can’t seem to find it on github though.”

So, for those in the same boat as me. Please use this instead.

Right click on the Item, Scripts > Download. This works wonder. You will get all your raw files in a zip file.

Still SPE but not scripted.

~ Scratching is as irresistible as Cocain. ~

How to check if COVEO is active in your instance…

  1. got to https://<your-sitecore-url>/coveo/rest and see if you get JSON back. If you don’t you know what’s not there.
  2. Use the following code. But, Coveo dlls need to be there. if they dont we will get an (duh!) error but try catch could help you out here.
    var activator = new Coveo.Service.Api.ConfigServiceBase.Activators.InstanceActivator();    
    model.IsCoveoActivated = activator.IsActivated();

3. simple is king. Check if a config file exists.     
model.IsCoveoActivated = 
System.IO.File.Exists("C:\\inetpub\\wwwroot\\App_Config\\Include\\Coveo\\Coveo.SearchProvider.Custom.config");

AND BOOM!

~ Hope is a dangerous emotion. ~

All about Sitecore’s webedit buttons… Better and more up to date instructions, than that Valtech blog

This is valtech blog: https://www.valtech.com/insights/sitecore-8-and-8.1-how-to-add-a-field-editor-button-to-a-component-in-experience-editor-mode/

This got me started, but I am using sitecore 9.3. so I thought I would write down the updated steps. for all of you out there that area reading this.

Just follow the steps;

  1. turn on your computer
  2. Open browser
  3. log on to Sitecore
  4. Start from the core database
    core database
  5. I created mine on this path /sitecore/content/Applications/WebEdit/Custom Experience Buttons/webedit button location on sitecore tree
  6. Make sure you have all the proper field names, use pipe separator for multiplecreate-webedit-with fields
  7. Once those are saved, go back to master database
  8. find your layout items, rendering, sub-layouts what whatever you want to add the buttons to.
  9. Find the Experience Editor Buttons field and add the controls in there.add webedit to your layout
  10. There you have it.webedit in action
  11. Close your computer and go outside for a walk.

 

~ Times are always changing, with every single tick or the clock.~

Make Sitecore look good Again. Tip #2012: Add custom CSS to Launchpad

If you are like me, you are looking at Sitecore Launchpad if you are looking at light or dark Visual Studio all day and night, and sometimes in your dreams.

03

I needed to make some lifestyle changes, so I decided to try to change the layout and look of the Launchpad. As usual planning and research and actually finding the time to do this took way longer than the actual task.

I went deep into Sitecore. Learned about injecting JS and CSS into pipelines here, Things like adding a button to Launchpad, Adding controls in Content Editor in the Core database. Watched youtube videos with weird titles.

But at the end of the day, what I wanted to accomplish was really simple.

Go to your core database and find this item. /sitecore/client/Applications/Launchpad/PageSettings/

Add a new Page-Stylesheet-file item with a link to your CSS file.

Screen Shot 2020-03-30 at 11.15.30 PM

Guess what? That’s it.

My Launchpad now looks like below.

Screen Shot 2020-03-30 at 11.17.23 PM

Want the CSS. Here is it.

.sc-launchpad-group-title{
	margin-bottom:15px;
}

.sc-launchpad-group-row{
	height:auto;
	width:170px;
}

.sc-launchpad-item{
	display:contents;
	width:170px;
	position:relative;
	height:45px;
}

.sc-launchpad-item .icon{
	width:40px;
	height:40px;
	float:left;
	border:none;
	margin:0px;
	margin-bottom:10px;
}

.sc-launchpad-item .icon img{
	width:30px;
	height:30px;
	margin:5px 0px 0px 0px;
}

.sc-launchpad-item .sc-launchpad-text{
	height:41px;
	width:130px;
	max-width:130px;
	margin-bottom:10px;
	background-color: #f7f7f7;
    background-image: -webkit-linear-gradient(white, #f7f7f7);
    background-image: -o-linear-gradient(white, #f7f7f7);
    background-image: linear-gradient(white, #f7f7f7);
	text-align: left;
    padding-top: 5px;
    padding-left: 5px;
}

.sc-launchpad-item .sc-launchpad-text:hover{
	background-color:white;
	background-image:none;
}

 

 

~ Don’t change what’s inside of you. Change what’s around you.~

See who is logged in to your Sitecore CM environment

Who had this problem where you have to make some changes to your CM server, you told the authors to get out, but they never leave. They love Sitecore so much you can’t get them out by themselves.

So, I wanted to know who is using the server at the time. and thus created a page that lists the logged-in users at that time.

Sitecore has this functionality on the kick users/boost user page. So, that’s where I started. Did you know /sitecore/admin/sessionsummary.aspx is a page that’s actually there. But it doesn’t work. I get 500 error. Screen Shot 2020-02-14 at 3.19.04 PM

 

So, Dotpeek it is and I made the following.

@{
	List<Sitecore.Web.Authentication.DomainAccessGuard.Session> newList = Sitecore.Web.Authentication.DomainAccessGuard.Sessions;
}
<div><h3>Maximum Sessions Allowed in this instance:</h3>  @Sitecore.Web.Authentication.DomainAccessGuard.MaximumSessions</div>
<div>
@if (newList.Any())
{
	<H3>logged in users:</H3>
	<table border="1">
	<tr>
		<td>Session ID</td>
		<td>User Name</td>
		<td>Created Date</td>
		<td>Last Request Date</td>
		<td>Active For (Minutes)</td>
	</tr>
	@foreach (var dg in newList)
	{
	<tr>
		<td>@dg.SessionID</td>
		<td>@dg.UserName</td>
		<td>
			@DateTime.Parse(dg.Created.ToString()).ToLocalTime()
		</td>
		<td>
			@DateTime.Parse(dg.LastRequest.ToString()).ToLocalTime()
		</td>
		<td>
			@((int)((dg.LastRequest - dg.Created).TotalMinutes))
		</td>
	</tr>
	}
	</table>
}
</div>

 

I stuck this in my /Sitecore/admin folder, or put it wherever you need.

This will give you following page.

Screen Shot 2020-02-14 at 3.22.24 PM

I added an auto-refresh on the page as well just for fun, you all know how to do that, right 🙂

Enjoy!!!

 

~ Fight, Flight, Food & Fuck, The four F’s of Life’s Basics. ~

“Sorry, There was an error: unauthorized_client” error when trying to log in with custom url on Sitecore 9.2 Azure

This was one of those Duh! errors, that looked like below.

Once upon a time, I was getting Sitecore ready to roll for a client on Azure. Sitecore spun everything up for us. I got the code copied over and everything started working. The first complaint the client had was those long complicated hostnames. i.e. https://mc-abcdef-1111-2222-3333-asdqwe-cm.azurewebsites.net, but that’s another blog post for another day.

I got everything working as the go-live date started approaching fast. Was time for a final clean up and set up and along came the custom domain name to map to that server. CD went fine. CM site showed up on the sm.website.com perfectly ok but alas! going to /Sitecore/login started erroring out. I freaked me out a little bit as I have not faced this error on my 4 years of setting this monster up.

First stop, I always bug those Sitecore support people. They are awesome and very responsive. They may block me soon for creating too many premature tickets but it gives me peace of mind knowing that someone else is on it other than me.

But how I fixed it?

Go to your SI server. Head on over to Azure app service editor. Find the Sitecore.IdentityServer.Host.xml file inside Config/production/ folder.

Screen Shot 2020-02-10 at 1.10.06 PM

and then you know what to do from the other more useful blog posts 🙂
Add this line inside <AllowedCorsOrigins> tag:

<AllowedCorsOriginsGroup1>http://cm.website.com|https://</AllowedCorsOriginsGroup1>

 

see, the mistake I did was not look inside the production folder above. the file you want is inside the production folder and not the one on the root. That one is empty. My bad.

 

OH! You also need to restart the app pool on the SI server. I have no idea how to do that on Azure. So, I restarted the app service. things started working as expected.

 

~ When in doubt, as an expert, & when you solve it, write it down for someone else. ~

 

@Html.Sitecore().Placeholder() | CS1061: ‘System.Web.WebPages.Html.HtmlHelper’ does not contain a definition for ‘Sitecore’ |Error on master page layout file

Sitecore is hard. But being everything in life is hard, I was setting up another Sitecore instance. everything was ready to go and when the time came. I hit the homepage.

Alas! the yellow screen of death.

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'Sitecore' and no extension method 'Sitecore' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 6:  	<div class="row">
Line 7:  		<div class="column--standard col-xs-12 col-lg-6 col-lg-push-3">
Line 8:  			@Html.Sitecore().Placeholder("page-details")
Line 9:  			@Html.Sitecore().Placeholder("more-top")
Line 10: 			@Html.Sitecore().Placeholder("content")
Source File: d:\home\site\wwwroot\Areas\CLIENT\Views\Master\StandardPage.cshtml    Line: 8

Compiler Warning Messages:
Warning: CS1702: Assuming assembly reference 'System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' matches 'System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263', you may need to supply runtime policy
Source Error:
[No relevant source lines]

Show Detailed Compiler Output:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3429.0

What the actual Eff, right? Check the dlls, they were the right version. Right before I was going to pull out the last three hairs on my head without critically thinking about the error, my colleague came up with the idea of checking the web.config in the Views folder.

And, there it was. web.config didn’t get deployed inside the folder. Once I had the file copied over, the view knew which dll to load and everything was peachy Dory.

 

~ Is web.config one word or two, grammatically? ~

Sitecore 9.2 on Azure Web App: Runtime error with no clue in logs

Sitecore was working fine in the morning. Then you went for coffee and things broke. Beyond your comprehension, you try to blame Sitecore devs for a flimsy application but its been all your fault (somehow)?

In my case, I kept getting this error everywhere. in /sitecore and outside. without showconfig and other tools, I felt helpless.

Screen Shot 2019-12-16 at 9.09.04 AM

At least the logs were generating. Every minute there was one new log with this text in it.Screen Shot 2019-12-16 at 9.09.50 AM

First time in my life seeing this. I felt like a Sitecore virgin in an Azure Orgy.

 

but fear not. Azure was helpful. Even when Sitecore slack, Google and StackExchange did not. I went as deep as deadlock resolving for a different version.

Lookey here: https://kb.sitecore.net/articles/910936

finally, Kiran Vai’s article set me straight.

https://sitecorebasics.wordpress.com/2018/12/25/troubleshoot-and-fix-crashing-sitecore-902-application-on-azure-app/

Logged on to Azure. Collected memory dump.

At first, it was of no use.

Screen Shot 2019-12-16 at 11.02.55 AM

I felt myself getting stuck in LIMBO.

but kept scrolling for that little glimmer of hope. and found this. Screen Shot 2019-12-16 at 11.03.34 AM

I flipped my table and went for a coffee.

When I came back. Restored the connectionstrings.config file. I did not even scroll down anymore. I did not even want to know why and how it got broken. I did not want to find out why Sitecore could not give me a yellow screen of death with this error. I just moved on with my life. And you should too….

 

 

~ Don’t try to change something, try so that something cannot change you. ~

Sitecore on Azure PAAS: how to get rid of the default azure page?

This one time in band-camp I was setting up Sitecore on azure. doing the usual

  • copy database
  • change connection strings
  • copy code
  • copy files
  • copy dlls and configs

but then the site homepage was not loading. It kept showing the default azure homepage.

Screen Shot 2019-12-12 at 4.09.46 PM

to fix this. Log on to the portal.

find your App Service > Configuration > Default Documents

add default.aspx and get rd of hostingstart.html

Screen Shot 2019-12-12 at 4.10.42 PM

and that’s the feeling you get when a wise person once said: “Voila!”

~ Water bottles are a first world problem, that ends up in the third world problem. ~

Sitecore 9 Dictionary – Nothing is working, no key, no value, no text at all

This must-have happened to one or two of us out there.

One fine evening I was setting up Sitecore. I started with CM. got the site working.

Now it’s time for CD. Got everything working but none of the texts that are from the Dictionary were showing up. Not even the Keys. It’s just empty.

Threw me into a loop of Reindex, republish, delete the .dat file. Clear cache, reset Dictionary cache, reindex, republish and so on…

But end of the day it was the site definition configuration. The DictionaryDomain was in the site configuration. but the hostname was still pointing to CM. so created another patch with a role:require for ContentDelivery and dictionary started working.

It’s a silly thing to look over but I did it, so I thought I should share.

 

~ When google doesn’t help, Think with your own head. ~