Sitecore 9 on Windows 8.1, my experience

XtremDev - Sebastian Tecsi | Sitecore Blog

There are a couple of articles about Sitecore 9 on a Windows 8.1 development machine, and since it’s bit out of hand for me to upgrade to Windows 10 I’ve decided to take the bull by the horns and finally do it. Even that I’ve lost a bet with @SitecoreClimber that will manage to install Sitecore 9 to my Windows 8.1 in fist-second week of the launch without any troubles.

Windows 8.1 does not have Powershell 5.1 as its needed by SIF, so you can install it from here, as Windows Management Framework 5.1 includes also Powershell 5.1. An alternative way it to use this command choco install powershell if you are using Chocolatey.

After a restart of the machine it’s time to install Sitecore Install Framework and Sitecore Fundamentals. So in a Windows Powershell opened as Administrator execute this:

Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2 Install-Module SitecoreInstallFramework…

View original post 411 more words

Downloading the Media item on WFFM from submission

I have seen that many developers are searching for a solution for downloading the media item on successful submission of a WFFM form, But I couldn’t find an exact solution over the internet and that’s where I thought of putting this to help the community.

So here is the solution.

  1. Add a field to your form and hide it using the tricks I explained in one of my previous posts. You can find that here- Hide a field on WFFM (No CSS & JS)
  2. Give that field a default value and that value should be the Media Item Id.
  3. Now come to the code. You need to create a custom save action to achieve this. Have a look at my code.
using System;
using System.Collections.Generic;
using System.Net;
using System.Web;
using Sitecore.Data;
using Sitecore.Diagnostics;
using Sitecore.WFFM.Abstractions.Actions;
using Sitecore.WFFM.Abstractions.Shared;
using Sitecore.WFFM.Actions.SaveActions;
using Sitecore.Data.Items;
using Sitecore;

namespace SitecoreTricks
{
 public class DownloadMediaOnSuccess : SendMessage
 {
 public DownloadMediaOnSuccess (ISettings settings, IMailSender mailSender) : base(settings, mailSender)
 {}

public override void Execute(ID formId, AdaptedResultList adaptedFields,
 ActionCallContext actionCallContext = null,
 params object[] data)
 {

 var formData = new Dictionary<string, string>();
 foreach (AdaptedControlResult acr in adaptedFields)
 {
 formData.Add(acr.FieldName, acr.Value);
 }
var MediaItemId = !string.IsNullOrEmpty(formData["FileToDownload"])
? formData["FileToDownload"]
: string.Empty;

var item = Context.Database.GetItem(new ID(MediaItemId));
 var mediaItem = (MediaItem) item;

HttpContext.Current.Response.Clear();
 HttpContext.Current.Response.ContentType = mediaItem.MimeType;
 HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("inline;filename=\"{0}\"", mediaItem.Name+"."+mediaItem.Extension));
 HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK;
 HttpContext.Current.Response.BufferOutput = true;
 mediaItem.GetMediaStream().CopyTo(HttpContext.Current.Response.OutputStream);
 HttpContext.Current.Response.Flush();
 HttpContext.Current.Response.End();

} 
 }
 }

That’s it. The PDF will be opened in the browser from there you can download it.

Reference: Learn how to hide a field on a WFFM form

Field Level Restrictions in Sitecore

Requirement: As an admin user, I want read only access on a field for a specific role.

Solution: First of all having read or write access on a particular field is not possible in Sitecore. So now the question is, what can be done in this situation? And the answers is, by restricting the field itself for required user or role. To achieve this, you have to break the inheritance of this field for the required role.

  1. Go to Role Manager and Create a new Role

Role

  1. Select the newly created role and add the required role in members list.

role-members

  1. Go to Security Editor and select the newly created role and then navigate to field (to be restricted)

Security-Editor

That’s it, we are done with restricting a field access for a particular role. Now, the field will not be visible for the selected role users on template item.

Hide a field on WFFM (No CSS & JS)

WFFM provides an inbuilt way to hide one or more fields form rendered for an end user. Of course, I am not gonna use any CSS or JS to achieve this, instead, I’ll show you to do this by using an inbuilt feature of WFFM.

  1. Go to Form Designer and select the field you want to hide and scroll the left bar and click on Edit button shown under the Rules section.

WFFM1

2. Clicking on Edit button will open a popup with some predefined conditions and actions. Search for the “Database” and select the “where the current database name compares to value”. Click on “compare to select the compare rule and from there select “Is Equal To” and then click on “Value” and enter your web database connection string name like “web”.

WFFM-Edit-Rule-1

3. Now select the “hide element” actions tab and click ok.

WFFM-Edit-Rule-2

that’s it. Save the changes and publish the form. Now, the selected filed will not be available in the browser.