Click here to Skip to main content
15,891,764 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i create a shortcut with C# for files with English names shortcuts created successfully but when i try to create a shortcut with Arabic name i get this error "Value does not fall within the expected range" The error in Target part.

Here is the code is use
WshShell shell = new WshShell();
                
                string shortcutAddress = des_cmb.Text + @"\" + name_txt.Text + ".lnk";
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = comment_txt.Text;
                //shortcut.Hotkey = "Ctrl+Shift+N";
                shortcut.Arguments = args_txt.Text;
                shortcut.WindowStyle = 1;//1 normal, 3 maximize, 7 minimize
                switch (style_cmb.SelectedIndex)
                {
                    case 0: { shortcut.WindowStyle = 1; break; }
                    case 1: { shortcut.WindowStyle = 3; break; }
                    case 2: { shortcut.WindowStyle = 7; break; }
                }
                shortcut.IconLocation = fileIcon;
                shortcut.WorkingDirectory = Path.GetDirectoryName(targetpath_txt.Text);
                shortcut.TargetPath = "\"" + targetpath_txt.Text + "\"";
                shortcut.Save();


Is there a way to create shortcuts to files with Arabic names without getting the error?

I use C# WinForms

What I have tried:

I tried to search for a fix but i didn't find any.
Posted
Updated 14-Oct-17 4:45am

Maybe this article could be of any help:
Windows IT Pro: Scripting Shortcuts That Contain Unicode[^]
Summarized, there are two steps:
- create the shortcut with a name containing only (dummy) ASCII characters.
- rename that shortcut with a name containing Unicode characters.
Hope this helps. Kindly.
 
Share this answer
 
I found a fix in this answer
c# - Create shortcut with Unicode character - Stack Overflow[^]
It create a shortcut successfully for a file with Unicode name like Arabic name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900