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. ~

New to Sitecore? Boss wants you to create something new. Read this and stop crying…

Wipe those tears off. Turn on your computer. Make sure your mouse and keyboard are plugged in and vaguely follow these steps below…

  • Find out the name of your new component, items, field, sections, etc…
  • Gather all requirements
  • THE SITECORE PART
    • Creating the template
      • Create the folder template (if needed), this is where the main item template will go in), comes in handy for organization and insert options.
      • Create the item template
        • Create the fields
          • Name the sections properly
          • Pick proper field type
        • Create standard values
          • Go to Options Tab > click on standard values
      • Create icons, insert options, validation rules, display names, etc
      • Create a template for the folder which will hold the above templates
        • set insert options for the above template
    • The Layout
      • Create Rendering
        • usually a controller rendering, View renderings are very common as well
        • Give the appropriate controller and action name
        • maybe even a Datasource Template
        • Thumbnails are useful for authors
      • Go back to the template
        • on standard values
          • set the presentation > detail
          • find the layout name
          • find the right placeholder name
            • look in layout.cshtml if needed
    • Layout > Placeholder settings
      • add the new template to allowed rendering
    • Content
      • Create a structure
      • create content
  • THE CODE PART
    • create controller
    • create Model
    • Create View
  • Deploy
    • build ( gulp is widely used)
  • Test
  • Check-in
    • Don’t forget the TDS items
  • Pull Request
  • Review
  • Enjoy Life!!!

Will add screenshots soon… until then you are on your own. Figure it out like the rest of us 😛

 

 

~ How many is a few? ~

 

Invalid GUID format error when publishing WFFM forms under Settings > Modules

I recently upgraded WFFM 2.4 running on Sitecore 7 to V9 running on Sitecore 9.

Among many other issues and fixes, there is one that I have not found the solution yet but there is always workarounds.

When I was publishing the Settings > Modules folder I saw this “Invalid GUID format” error.

After much debugging, i found that the ‘Sample forms’ has broken GUID in tracking field (or something along that line, from all the other search results)

To find that had to borrow the below code. Which confirmed the suspicion.

<%@ Page Language="C#" %>
<%@ Import Namespace="Sitecore" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Diagnostics" %>
<%@ Import Namespace="Sitecore.Links" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>Find broken tracking field links</title>
</head>
<body>
 <form runat="server">
 <asp:GridView runat="server" ID="Culprits" AutoGenerateColumns="False" ItemType="Sitecore.Data.Items.Item">
 <Columns>
 <asp:TemplateField HeaderText="ID">
 <ItemTemplate>
 <a href="/sitecore/shell/Applications/Content Manager/Default.aspx?fo=<%#Item.ID%>" target="_blank"><%#Item.ID%></a>
 </ItemTemplate>
 </asp:TemplateField>
 <asp:BoundField HeaderText="ID" DataField="ID" />
 <asp:BoundField HeaderText="Path" DataField="Paths.Path" />
 </Columns>
 <EmptyDataTemplate>
 <p>No broken tracking fields found.</p>
 </EmptyDataTemplate>
 </asp:GridView>
 </form>
</body>
</html>
 

 protected override void OnLoad(EventArgs e)
 {
 var database = Database.GetDatabase("master");
 var suspects = database.SelectItems("fast://*[@__Tracking != '']").OrderBy(item => item.Paths.Path).ToList();
 Culprits.DataSource = GetCulprits(suspects, Globals.LinkDatabase);
 DataBind();
 }
 
 private IEnumerable GetCulprits(IEnumerable suspects, LinkDatabase linkDatabase)
 {
 var culprits = new List();
 foreach (Item suspect in suspects)
 {
 try
 {
 linkDatabase.UpdateReferences(suspect);
 }
 catch (FormatException)
 {
 culprits.Add(suspect);
 }
 }
 return culprits;
 }

After that, I just didn’t publish those sample forms. Everything else worked fine. If someone knows a definite solution please let me know.

~ When in doubt, don’t think about it. ~