File.encrypt method

I'm just trying to do a simple encrypt of a file.  I'm getting a System.IO.IOException thrown when the method executes.  Am I mis-interpreting this method   The documentation states that it's available in C#.  Here's a snippet of the important parts.

using System;
using System.IO;
using System.Security.AccessControl;

try

{

File.Encrypt("G:\\test.tx1");   //this is an NTFS partition

}

catch (IOException er)

{

MessageBox.Show(er.ToString(), "error", MessageBoxButtons.OK);

}

The error is System.IO.IOException: The request is not supported.  Then points back to the line containing the File.Encrypt statement above.



Answer this question

File.encrypt method

  • clearlydotnet2

    Yes, all true, running as an app, user is admin, file is not locked/read-only.  I'm clueless.  Tongue Tied
  • Kranti

    No, it's the root drive for my XP install.  I haven't tried it on a non-NTFS partition.
  • thedawn

    Here's the exception thrown.

    System.IO.IOException: The request is not supported.

    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.Encrypt(String path)
    at encryptFile.Form1.Encrypt_Click(Object sender, EventArgs e) in G:\....cs:line 41


  • CougarT

    I have XP-HE on the computer I'm developing on as my laptop with XP-PE is being repaired. That's the problem.
  • justcallmemasta

    Is G: a network drive


  • Vi_High_0017

    This does not allow me to Encrypt the file at the file system level.  The checkbox is disabled, the drive is an NTFS and I'm the administrator.  Thanks.
  • Mindaugas Luko?ius

    This would not work on an non-NTFS partition as stated in the documentation. I hope you are running this as an application vs from ASP.NET Check if the  user has enough permissions to encrypt the file.

    Alternatively check is the file is not locked by some other process and it has Read/Write ability i.e. it is not marked as read-only.

    Regards,
    Saurabh Nandu
    www.MasterCSharp.com
    www.AksTech.com

  • GPK2005

    try if you can manually encrypt the file from Windows Explorer - right-click the file, select Properties from the context menu, click on Advance button on the general tab and then select "Encrypt contents data". This would manually encrypt the file. 

    I was looking at the Encrypt method's IL and it raises the request is not supported error in case your program does not have permissions or you drive is not NTFS.  

    Regards,
    Saurabh Nandu
    www.MasterCSharp.com
    www.AksTech.com

  • File.encrypt method