title: Use a ShellFile object using Windows API Code Pack for Microsoft
body: <p>Windows API Code Pack for Microsoft can be downloaded from <a href="http://archive.msdn.microsoft.com/WindowsAPICodePack" rel="nofollow noreferrer">here</a>. That is a really nice library and it has great examples. For example if I open the solution WindowsAPICodePack10 that comes in the zip from downloading the code pack (it only contains the libraries I added a win forms and wpf application)</p>
  
  <p><img src="https://i.stack.imgur.com/Rqyyx.png" alt="enter image description here"></p>
  
  <p>then I am able to use the library very easily for example in my wpf application I can drag:</p>
  
  <p><img src="https://i.stack.imgur.com/fslPT.png" alt="enter image description here"></p>
  
  <p>ExplorerBrowser user control (note I have to add references to the libraries that came with the solution)</p>
  
  <p>and then with a button I can populate that control with this lines of code:</p>
  
  <pre><code>        // Create a new CommonOpenFileDialog to allow users to select a folder/library
          CommonOpenFileDialog cfd = new CommonOpenFileDialog();
  
          // Set options to allow libraries and non filesystem items to be selected
          cfd.IsFolderPicker = true;
          cfd.AllowNonFileSystemItems = true;
  
          // Show the dialog
          CommonFileDialogResult result = cfd.ShowDialog();
  
          // if the user didn't cancel
          if (result == CommonFileDialogResult.Ok)
          {
              // Update the location on the ExplorerBrowser
              ShellObject resultItem = cfd.FileAsShellObject;
              explorerBrowser1.NavigationTarget = resultItem;
              //explorerBrowser1.Navigate(resultItem);
          }
  </code></pre>
  
  <p>and after that I am able to have something like:</p>
  
  <p><img src="https://i.stack.imgur.com/QOjYz.png" alt="enter image description here"></p>
  
  <p>That is amazing but I don't understand Microsoft. If they give you those libraries they should make it easy to customize that user control. the reason why I downloaded those libraries is because I need to place files from a specific directory on a stackpanel and be able to have the same functionality that you get with files on explorer (able to drag files, get context menu when right clicking file, dropping files to that container etc)</p>
  
  <p>anyways I don't need all that functionality. from studing the library I think that user control contains a ShellContainer object and it's childern are ShellFiles maybe. </p>
  
  <p>So from this library I will like to create a ShellFile object and place it in a StackPanel. after tedious studing of the library I finally found out how to instantiate an object from shellFile (ShellFile class is abstract) :</p>
  
  <pre><code>string filename = @"C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe"; \\random file
  ShellFile shellFile = ShellFile.FromFilePath(filename);
  </code></pre>
  
  <p>now it will be nice if I could place that file in a container. I am not able to instantiate a ShellConteiner object becaue it is abstract too. so how Will I bee able to place that shell file on a canvas for example?</p>
  
  <p>or maybe I could extract the properties that I need and create a user control that will represent a shellFile. I know how to get the thumbnail I can do something like:</p>
  
  <pre><code>        string filename = @"C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe";
  
          ShellFile shellFile = ShellFile.FromFilePath(filename);
          System.Drawing.Bitmap btm = shellFile.Thumbnail.ExtraLargeBitmap;
  </code></pre>