2016-03-27 13 views
0

Dinamik olarak kısayol oluşturmak için aşağıdaki kodu kullanıyorum. Ancak, klasör adında Tay dili, yunan dili gibi unicode karakterler olduğunda targetPath Argüman istisnası atar.Klasör adının unicode karakterlere sahip olduğu Kısayol Oluşturma

dosya sisteminden
IWshRuntimeLibrary.WshShell shell = new WshShell(); 
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation); 
shortcut.Description = "My shortcut description"; // The description of the shortcut 
shortcut.WorkingDirectory = currentPath; 


shortcut.TargetPath = targetFileLocation;     // The path of the file that will launch when the shortcut is run 
shortcut.Save(); 
+0

Sen gerekebilir adlı bileşeni seçin işlenemeyen unicode karakterleri için (d1234 gibi) yeni dizge için mantık oluşturmak. – Ian

cevap

1

Referans Shell32.dll, "ref ekle ..." iletişim kutusunun COM sekmesine gidin ve "Microsoft Shell Kontrolleri Ve Otomasyon"

string destPath = @"c:\temp"; 
string shortcutName = @"नमस्ते.lnk"; 

// Create empty .lnk file 
string path = System.IO.Path.Combine(destPath, shortcutName); 
System.IO.File.WriteAllBytes(path, new byte[0]); 
// Create a ShellLinkObject that references the .lnk file 
Shell32.Shell shl = new Shell32.ShellClass(); 
Shell32.Folder dir = shl.NameSpace(destPath); 
Shell32.FolderItem itm = dir.Items().Item(shortcutName); 
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink; 
// Set the .lnk file properties 
lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe"; 
lnk.Description = "nobugz was here"; 
lnk.Arguments = "sample.txt"; 
lnk.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
lnk.Save(path); 
+1

Ben nobugz. Oradaydım. Sadece bu senin kodunmuş gibi davranma, atıfta bulunmalısın. –

İlgili konular