none
Shortcut created in long file path not accessible RRS feed

  • Question

  • We have created a folder in very long path (400 characters) using C# code. Have used "\\?\" as described in the following article to create this folder:

    https://stackoverflow.com/questions/5188527/how-to-deal-with-files-with-a-name-longer-than-259-characters

    Now when we try to create a shortcut inside this folder, shortcut gets created but is not accessible. It throws following error:

    

    If we create a file inside this folder, we are successfully able to open the file. So problem is there only with file type shortcut.

    Any advice would be helpful..


    Please remember to mark the reply as answer if it has helped.

    Saturday, May 11, 2019 7:18 AM

All replies

  • Hi Neelesh,

    Thank you for posting here.

    Based on your description, you want to solve the error when you create a shortcut inside the long path folder.

    I have created a long path using Delimon.Win32.IO. Now, I want to know how do you create the shortcut inside the folder. I even tried to create a shortcut in the folder manually, but I find it only create a new folder. You could refer to the following picture.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 13, 2019 5:59 AM
    Moderator
  • Hi Neelesh,

    Thank you for posting here.

    Based on your description, you want to solve the error when you create a shortcut inside the long path folder.

    I have created a long path using Delimon.Win32.IO. Now, I want to know how do you create the shortcut inside the folder. I even tried to create a shortcut in the folder manually, but I find it only create a new folder. You could refer to the following picture.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I am not sure about the API that you have used. I am using .net framework 4.6.2 and used following code to create the directory at very long path:

    string reallyLongDirectory = @"\\?\C:\Test\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                reallyLongDirectory = reallyLongDirectory + @"\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                reallyLongDirectory = reallyLongDirectory + @"\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGH    IJKLMNOPQRSTUVWXYZ\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

                Directory.CreateDirectory(reallyLongDirectory);

    I also modified the config file to include:

    <configuration>
          <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
      </runtime>
    </configuration>

    In this folder that I created, I am able to see all standard options to create new file or folder or shortcut when I right click.


    Please remember to mark the reply as answer if it has helped.

    Monday, May 13, 2019 6:50 AM
  • Hi 

    Thanks for the feedback.

    I used the following code to create a long path folder based on the link.

    private void Button1_Click(object sender, EventArgs e)
            {
                DialogResult result = folderBrowserDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    folderBrowserDialog1.Description = "The path to a specified file consists of one or more components, separated by a special character (a backslash), with each component usually being a directory name or file name, but with some notable exceptions discussed below. It is often critical to the system's interpretation of a path what the beginning, or prefix, of the path looks like. This prefix determines the namespace the path is using, and additionally what special characters are used in which position within the path, including the last character.";
                    string sdir = folderBrowserDialog1.SelectedPath;
                    if (sdir != null)
                    {
                        for (int i = 0; i < 20; i++)
                        {
                            Guid guid = Guid.NewGuid();
                            sdir = Delimon.Win32.IO.Path.Combine(sdir, guid.ToString());
                            Delimon.Win32.IO.Directory.CreateDirectory(sdir);
    
                        }
                    }
                }
                
            }

    After creating the folder, I could not create the shortcut for this.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 13, 2019 8:04 AM
    Moderator
  • Can you please try with the method I suggested and see if you can create shortcut and access it?

    Please remember to mark the reply as answer if it has helped.

    Monday, May 13, 2019 9:28 AM
  • Any inputs anybody?

    Please remember to mark the reply as answer if it has helped.

    Monday, May 13, 2019 3:22 PM
  • Hi Neelesh,

    Thanks for the feedback.

    I have reproduced your problem according to your code. I think the following link is helpful for you.

    It describes that how to deal with Maximum Path Length Limitation.

    https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 14, 2019 1:58 AM
    Moderator
  • Hi Neelesh,

    Thanks for the feedback.

    I have reproduced your problem according to your code. I think the following link is helpful for you.

    It describes that how to deal with Maximum Path Length Limitation.

    https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thank you for sharing the link. I have seen this link and it also talks about using "\\?\" approach to construct the long file path (upto ~32000 chars) but how will it help to make shortcut accessible?

    Please remember to mark the reply as answer if it has helped.

    Tuesday, May 14, 2019 2:34 AM
  • Hi 

    Thanks for the feedback.

    Please pay attention to that link, it has the following sentence.

    >>Starting in Windows 10, version 1607, MAX_PATH limitations have been removed from common Win32 file and directory functions. However, you must opt-in to the new behavior.

    After the sentence, it has some solutions to the long path.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 15, 2019 7:43 AM
    Moderator
  • Yes I tried that. That property in registry is not available in any other windows but windows 10. Even in windows 10, it is not working as expected and is not allowing to create folder with long path. :(

    Please remember to mark the reply as answer if it has helped.

    Thursday, May 16, 2019 2:47 PM
  • Hi Neelsh,

    Thanks for the feedback.

    In fact, your problem is not related to c#. Therefore, I suggest that you could get support in the following link.

    https://support.microsoft.com/en-us/hub/4338813/windows-help?os=windows-10​​​​​​​

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 17, 2019 6:10 AM
    Moderator
  • Well it is related to c#. As Directory.CreateDirectory API allows to create the folder at long path using "\\?\", do we have any API to create the shortcut as well at the long path using "\\?\" or some other technique? I am using Shell32 presently and it doesn't work if shortcut path starts with "\\?\".  I also tried WSH API but that also has the same problem.


    Please remember to mark the reply as answer if it has helped.

    Friday, May 17, 2019 2:17 PM