Surendra Sharma

Surendra Sharma

Search This Blog

Friday, August 26, 2016

How to get media library extension and mime type programmatically in Sitecore



One of my colleague asked me that how to get extension of uploaded file in Sitecore media library programmatically?

Here are different pointers which may be useful for you while working with media library 

·         You can get media library item in LinkField type from Sitecore.Data.Fields namespace.

·         LinkField.TargetItem -> gives reference of media library item.

·         Sitecore.Resources.Media.MediaManager.GetMediaUrl(linkField.TargetItem) -> Return media links

·         By default, link extension is “.ashx

·         Get the extension and mime type of media library item by using below code

//Return extension like gif
string mediaItemExtension = linkField.TargetItem.Fields["Extension"].Value;

//Return mime type like image/gif
string mediaItemMimeType = linkField.TargetItem.Fields["Mime Type"].Value;

·         You can also view both of these fields in Sitecore content tree as


Media Item
Media item
  
·         Let me cover one important entry in web.config file for media library item extension.
<!--  MEDIA - USE FILE EXTENSION IN ITEM NAMES
      Indicating whether to include a file extension when generating an item name from a file name.
      Default value: "false"
-->
<setting name="Media.IncludeExtensionsInItemNames" value="false"/>

·         As comments above explain that if you want to include extension in media item name then set this property as true and when you upload any file in media library for example “1.JPG” then after uploading, Sitecore give its name as “1 jpg” as shown in below image. By default this value is false and for uploading “1.JPG”, Sitecore name it as “1” as shown in first image.

Media Item with extension
Media item with extension

Please leave your comments or share these tip if it’s useful for you.

Monday, August 15, 2016

In just 1 hour - Implement Organization’s Password Policies in Sitecore



Today is very special day for me for three reasons

1.    I am celebrating 70th Independence Day of India.
2.    This is my 250th blog post
3.    I got new domain name for my blog as http://www.sitecorelessons.com/
  
On this special occasion, I am going to publish my second eBook which is available FREE to download. 

This eBook is about implementing password policy in Sitecore. 

In almost all the web application developers need to implement password policies. This guide covers all possible policies and their implementation technics with code in Sitecore. This guide covers implementation of below policies


              Minimum Password Length
              Consecutive Unsuccessful Login Attempts
              Password Complexity
              Forgot Password
              Password Expiration
              Change Password

After going through this guide, one should able to implement all these policies in less than 1 hour.
 
I tried my best to include all the scenarios that are associated with password policies management.

You can read and freely download this developer’s guide:





Please leave your comments or share this guide if it’s useful for you.

Getting new name of blog on 15 Aug 2016 - www.sitecorelessons.com




Independence Day greetings to you all. Today is 15th August 2016 and I am celebrating 70th Independence Day of my greattttt country India.

On this great day, I am happy to announce that my blog is getting new name http://www.sitecorelessons.com

http://surendrasharmadotnet.blogspot.com blog started on May 4, 2010. Since that day I have blogged nearly 250 blog posts and have witnessed over 100 thousand views on this blog. 

This blog was started as a learning lessons collection of personal experienced code and slowly it turned out to be a place for the coder enthusiast to talk Sitecore, .NET and SQL.

I really want to thank everyone for your kind support.