Example 1: shell32.dll c# example
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();
}
Example 2: 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);
}
}
Example 3: shell32.dll c# example
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;
}
Example 4: shell32.dll c# example
//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);
}
}
Example 5: shell32.dll c# example
public static string GetLnkTarget(string lnkPath)
{
try
{
var shl = new Shell32.Shell(); // Move this to class scope
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;
return lnk.Target.Path;
}
catch (Exception)
{
return lnkPath;
}
}
Example 6: shell32.dll c# example
public static void UnZip(string zipFile, string folderPath)
{
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
Shell32.Shell objShell = new Shell32.Shell();
Shell32.Folder destinationFolder = objShell.NameSpace(folderPath);
Shell32.Folder sourceFile = objShell.NameSpace(zipFile);
foreach (var file in sourceFile.Items())
{
destinationFolder.CopyHere(file, 4 | 16);
}
}
Example 7: shell32.dll c# example
private static void advanceBackgroundSlider()
{
//Display the Desktop via the COM component Shell32.dll
Shell32.Shell objShell = new Shell32.Shell();
objShell.ToggleDesktop();
// Simulate Ctrl + Space to deselect anything that may be selected
SendKeys.SendWait("^( )");
// Simulate pressing Shift + F10 to open Desktop context menu
SendKeys.SendWait("+{F10}");
// Simulate pressing N to execute the “Next desktop background” command
SendKeys.SendWait("{N}");
}
Example 8: shell32.dll c# example
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;
}
}
}
Example 9: shell32.dll c# example
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);
}
Example 10: shell32.dll c# example
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);
}