title: Techniques to save files from ActiveX (protected mode IE)
body: <p>i have an ActiveX.</p>
  
  <blockquote>
    <p>ActiveX means:</p>
    
    <ul>
    <li>Internet Explorer</li>
    <li>native binary code</li>
    <li>running from a dll (.ocx)</li>
    <li>in Protected Mode</li>
    </ul>
  </blockquote>
  
  <p>The user would like to save some content. i would like to show a <strong>Save As</strong> dialog, then save to the location they said.</p>
  
  <p>Since the process hosting my ActiveX is running at a <strong>Low</strong> integrity level, the code cannot save to the user's requested location.</p>
  
  <p>Since the process hosting my ActiveX is running in Internet Explorer's Protected mode, the code cannot save to the user's requested location.</p>
  
  <p>Instead the files are silently saved to a location that the user did not request.</p>
  
  <p>Instead the files are silently saved to a location where the end-user is not able to find them.</p>
  
  <p>Is there any suggestions of how to handle this?</p>
  
  <h2>Bonus Chatter</h2>
  
  <p>What is the user trying to save to their hard drive? It doesn't matter to the question. But pretend:</p>
  
  <ul>
  <li>it's a few hundred megabyte 3D cad mesh </li>
  <li>it's a GIS imagery dump</li>
  <li>it's a PDF</li>
  <li>it's a PNG</li>
  <li>it's a text file</li>
  </ul>
  
  <h2>Additional Reading</h2>
  
  <p>Internet Explorer's <em>protected mode api</em> does allow addins to show a savedialog:</p>
  
  <pre><code>IEShowSaveFileDialog(this.Handle, "Eden.3ds", 
        GetUserDocumentsFolder(), null, 
        "3D Studio File|*.3ds|GIS Imagery|*.kvm|Adobe Acrobat File|*.pdf|All Files|*.*|"
        null, 0, 
        OFN_ENABLESIZING | OFN_PATHMUSTEXIST,
        ref destinationPath, ref stateCookie);
  </code></pre>
  
  <p>and then save the file using that <em>cookie</em> that save provided:</p>
  
  <pre><code>IESaveFile(stateCookie, sourcefilename);
  </code></pre>
  
  <p>Where <code>sourcefilename</code> is going to be a file that i managed to save somewhere (which is another question).</p>
  
  <h2>Bonus Reading</h2>
  
  <blockquote>
    <h2><a href="http://msdn.microsoft.com/en-us/library/bb250462%28VS.85%29.aspx#wpm_sftup" rel="nofollow">Understanding and Working in Protected Mode Internet Explorer</a></h2>
    
    <p><a href="http://msdn.microsoft.com/en-us/library/bb250462%28VS.85%29.aspx#wpm_sftup" rel="nofollow">Saving Files to the User Profile</a></p>
    
    <p>Some extensions need to save files to a particular location so that users or applications can later find the files. The following steps show how to save a file outside of a low integrity location:</p>
    
    <p>Create a temporary version of the file in %userprofile%\AppData\LocalLow. Remember to delete the temporary file after the file is sucessfully saved.</p>
    
    <p>Call <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/security/protmode/reference/functions/IEShowSaveFileDialog.asp" rel="nofollow"><code>IEShowSaveFileDialog</code></a> with the location of the user's profile folder to prompt the user to save the file in a different location. If the user accepts the <strong>Save As</strong> dialog, <strong>IEShowSaveFileDialog</strong> returns the chosen destination folder.</p>
    
    <p>Call <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/security/protmode/reference/functions/IESaveFile.asp" rel="nofollow"><code>IESaveFile</code></a> with the location of the temporary file saved in Step 1.</p>
    
    <p>When you do this, Protected Mode's user broker copies the file from the temporary location to the location selected by the user.</p>
  </blockquote>