SHFileOperation Problem in C# (FOF_SIMPLEPROGRESS )

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • narsys
    New Member
    • Mar 2008
    • 1

    SHFileOperation Problem in C# (FOF_SIMPLEPROGRESS )

    I'm using SHFileOperation in my project. Everything is ok but something goes wrong when I want to use FOF_SIMPLEPROGR ESS falg. when I set it it doesn't work. I can't see nothing! if I use ansi version(without CharSet) it generates an exception!!

    here is my code:
    Code:
            [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
            public struct SHFILEOPSTRUCT
            {
                public IntPtr hwnd;
                public UInt32 wFunc;
                [MarshalAs(UnmanagedType.LPWStr)]public string pFrom;
                [MarshalAs(UnmanagedType.LPWStr)]public string pTo;
                public UInt16 fFlags;
                public Int32 fAnyOperationsAborted;
                public IntPtr hNameMappings;
                [MarshalAs(UnmanagedType.LPWStr)]public string lpszProgressTitle;
            }        
    public class FileOperation
    {
          public const UInt16 FO_MOVE = 0x0001;
          public const UInt16 FO_COPY = 0x0002;
          public const UInt16 FO_DELETE = 0x0003;
          public const UInt16 FO_RENAME = 0x0004;
    }
    
    public class FILEOP_FLAGS
    {
    
         public const UInt16 FOF_MULTIDESTFILES = 0x0001;
         public const UInt16 FOF_CONFIRMMOUSE = 0x0002;
         public const UInt16 FOF_SILENT = 0x0004;  // don't create progress/report
         public const UInt16 FOF_RENAMEONCOLLISION = 0x0008;
         public const UInt16 FOF_NOCONFIRMATION = 0x0010; 
         public const UInt16 FOF_WANTMAPPINGHANDLE = 0x0020;             
         public const UInt16 FOF_ALLOWUNDO = 0x0040;
         public const UInt16 FOF_FILESONLY = 0x0080; // on *.*, do only files
         public const UInt16 FOF_SIMPLEPROGRESS = 0x0100; 
         public const UInt16 FOF_NOCONFIRMMKDIR = 0x0200; 
         public const UInt16 FOF_NOERRORUI = 0x0400; // don't put up error UI
         public const UInt16 FOF_NOCOPYSECURITYATTRIBS = 0x0800; 
         public const UInt16 FOF_NORECURSION = 0x1000;     
         public const UInt16 FOF_NO_CONNECTED_ELEMENTS = 0x2000; 
         public const UInt16 FOF_WANTNUKEWARNING = 0x4000;          
         public const UInt16 FOF_NORECURSEREPARSE = 0x8000;
    }
    
    [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
    public static extern int SHFileOperation([MarshalAs(UnmanagedType.Struct)]ref SHFILEOPSTRUCT lpFileOp);

    I'm using it like this:

    Code:
    FileFolder.SHFILEOPSTRUCT str = new FileFolder.SHFILEOPSTRUCT();
                
    str.fFlags =  FileFolder.FILEOP_FLAGS.FOF_SIMPLEPROGRESS;
    str.pFrom = "c:\\test1.txt\0\0";
    str.pTo = "d:\\test1.txt\0\0";
    str.hwnd = this.Handle;
    str.fAnyOperationsAborted = 0;
    str.hNameMappings = IntPtr.Zero;
    //it does'nt apper in the dialog box
    str.lpszProgressTitle = "yesssssssssssssss";
    str.wFunc = FileFolder.FileOperation.FO_COPY;
    FileFolder.SHFileOperation(ref str);
    if (str.fAnyOperationsAborted!=0)
    {
            MessageBox.Show("Abroted");
    }
Working...