Arsak
0
Q:

shell32.dll c# example

public void ZipFile(string Input, string Filename)
    {
        Shell32.Shell Shell = new Shell32.Shell();
        
        //Create our Zip File
        CreateZipFile(Filename);

        //Copy the file or folder to it
        Shell.NameSpace(Filename).CopyHere(Input,0);
          
        //If you can write the code to wait for the code to finish, please let me know
        System.Threading.Thread.Sleep(2000);

        }
    }
0
        /// <summary>
        /// extract icon from link file</summary>
        public static Bitmap extractLnkIcon(string path)
        {
            #if !MONO
            try
            {
                var shl = new Shell32.Shell();
                string lnkPath = System.IO.Path.GetFullPath(path);
                var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
                var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));
                var lnk = (Shell32.ShellLinkObject)itm.GetLink;

                String strIcon;
                lnk.GetIconLocation(out strIcon);
                Icon awIcon = Icon.ExtractAssociatedIcon(strIcon);

                return awIcon.ToBitmap();
            }
            catch (Exception e)
            {
                Program.log.write("get exe icon error: " + e.Message);
            }

            return null;
            #else
            return null;
            #endif
        }
0
        public static bool CopyFontToWindowsFontFolder(string fontFilePath)
        {
            FileInfo fontFile = new FileInfo(fontFilePath);
            if (!fontFile.Exists)
                return false;

            var windowsFontFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            var shell = new Shell32.Shell();
            var destinationPath = Path.Combine(windowsFontFolderPath, Path.GetFileName(fontFilePath));
            var folder = shell.NameSpace(windowsFontFolderPath);
            folder.CopyHere(fontFilePath, 32);

            return true;
        }
0
public void CreateZipFile(string filename)
    {
        //Create the header of the Zip File 
        System.Text.ASCIIEncoding Encoder = new System.Text.ASCIIEncoding();
        string sHeader = "PK" + (char)5 + (char)6;
        sHeader = sHeader.PadRight(22, (char)0);
        //Convert to byte array
        byte[] baHeader = System.Text.Encoding.ASCII.GetBytes(sHeader);

        //Save File - Make sure your file ends with .zip!
        FileStream fs = File.Create(filename);
        fs.Write(baHeader, 0, baHeader.Length);
        fs.Flush();
        fs.Close();
        fs = null;
    } 
0
        public void                     onStartup()
        {
            Shell32.Shell               shell = new Shell32.Shell();
            Shell32.Folder              objFolder = shell.NameSpace(@"C:\Windows");

            this.files.Clear();
            foreach (string name in ColumnListPerName)
                this.files.Columns.Add(name);
            foreach (int id in ColumnListPerID)
            {
                string header = objFolder.GetDetailsOf(null, id);
                if (String.IsNullOrEmpty(header))
                    break;
                while (this.files.Columns.Contains(header))
                    header += "_";
                header = header.Replace("'", "_").Replace("’", "_");
                Debug.WriteLine("creating column named " + header);
                this.files.Columns.Add(header);
            }

            this.files.Columns["ID"].DataType = Type.GetType("System.Int32");
            this.files.Columns[objFolder.GetDetailsOf(null, 26).Replace("'", "_").Replace("’", "_")].DataType = Type.GetType("System.Int32");
            //this.files.Columns["Longueur"].DataType = Type.GetType("System.TimeSpan");
            this.files.Columns["URI"].DataType = typeof(System.Uri);
            ProcessLibraries();
            this.files.AcceptChanges();
        }
0
        public Main()
        {
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            SplitView.SplitPosition = this.Width / 2;

            m_Shell = new Shell32.ShellClass();
            m_RootShell = m_Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES);

            InitializeIconFolder();
            FillLocalView(m_RootShell);
        }
0
        public SharpFTP()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            SplitView.SplitPosition = this.Width / 2;

            m_Shell = new Shell32.ShellClass();
            m_RootShell = m_Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES);

            InitializeIconFolder();
            FillLocalView (m_RootShell);
        }
0
        private static void CollectFiles(string folder)
        {
            Shell32.Shell shell = new Shell32.Shell();
            Shell32.Folder objFolder = shell.NameSpace(folder);

            foreach (Shell32.FolderItem2 item in objFolder.Items())
            {
                if (item.IsFolder)
                    CollectFiles(item.Path);
                else
                {
                    if (!item.Type.ToUpper().StartsWith("MP3") && !item.Type.ToUpper().StartsWith("MPEG"))
                    {
                        LogError(item.Name + " has unsuupported file type of " + item.Type);
                        continue;
                    }
                    FileData fileData = new FileData();
                    fileData.name = item.Name;
                    fileData.size = item.Size;
                    fileData.modified = item.ModifyDate;
                    fileData.path = item.Path;
                    fileData.type = item.Type;
                    int.TryParse(objFolder.GetDetailsOf(item, yearID), out fileData.year);
                    string properName = fileData.name.Split(new char[] { '.' })[0];
                    if (dict.ContainsKey(fileData.size))
                    {
                        LogError(fileData.name + " clashed with " + dict[fileData.size].name);
                        count++;
                    }
                    dict[fileData.size] = fileData;
                }
            }
        }
0
        public static void ZipFile(string Input, string Filename)
        {
            Shell32.Shell Shell = new Shell32.Shell();

            //Create our Zip File
            CreateZipFile(Filename);

            //Copy the file or folder to it
            Shell.NameSpace(Filename).CopyHere(Input, 0);

            //If you can write the code to wait for the code to finish, please let me know
            System.Threading.Thread.Sleep(1000);
        }
0
        //Read above for copy instructions
        private static void Copy(string startFile, string folderPath)
        {
            if (!File.Exists(startFile))
                throw new FileNotFoundException();

            if (!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);

            Shell32.Shell objShell = new Shell32.Shell();
            Shell32.Folder destinationFolder = objShell.NameSpace(folderPath);
            Shell32.Folder sourceFile = objShell.NameSpace(startFile);
            foreach (var file in sourceFile.Items())
            {
                destinationFolder.CopyHere(file, 16);
            }
        }
0

New to Communities?

Join the community