Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

VS says path name must be less than 260 characters. It is less, so why the message

I'm trying to start a new visual studio 2017 C# project and have selected it to be an MVC project with the web API checkbox checked.  I've also checked the add unit test checkbox and changed the authentication to single user.  After I click OK I'm getting this message.

the specified path file name or both are too long. the fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.  The fully qualified file name is D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin\QAForumSolution which is 103 characters.
Why am I getting this message?
Avatar of Nikoloz Khelashvili
Nikoloz Khelashvili
Flag of Georgia image

The possible reason is, solution needs to create files to be created after debugging, which makes file full length longer.

MVC projects include some jquery libraries as well, so, check your solution straight in  D:\OneDrive\Documents\  folder and check it
Avatar of sarabande
the path you showed is a directory path. you have to add subfolders like Debug and project file names. if d: is not a local harddisk but a network drive, you also may consider that vs wants to resolve the name to an UNC path.

if nothing of those applies, you may close the solution in vis, then open the project file (.csproj) with a text editor and search for long path names.

Sara
Avatar of AlHal2

ASKER

HI Nikoloz,

Please can you explain what you mean by
check your solution straight in  D:\OneDrive\Documents\  folder and check it
I have to select a folder for the solution before I press the OK button to create it.

Hi Sarabande,

This is the longest path I could find but is still only 179 characters.

D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin\QAForumSolution\UI\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
Are you using any NuGet packages?  Are you using any third-party controls?

-saige-
Avatar of AlHal2

ASKER

I've not downloaded anything for the project.  However MVC and web API projects have lots of stuff by default before the user does anything.
Can you created your project in folder D:\OneDrive\Documents and check the max length of the file? It is adding jquery libraries as well. It is depended on the options you check to include and MVC project version
I would just junction a shorter path to D:\OneDrive\Documents\Courses\QAASPNETMVC
User generated image
Avatar of AlHal2

ASKER

Hi Nikoloz,

It worked creating the project in the C drive.  The longest path in the scripts directory is
C:\Users\ahalp\source\repos\QAForumSolution\UI\Scripts\jquery.validate.unobtrusive.min.js
This is only 90 characters.

Do you think the problem could have been caused by using OneDrive or the fact that the previous filepath had spaces?  https://onedrive.live.com/about/en-gb/
SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Open powershell window in your created solution and execute the following command to get fullname length of the files in the directory

dir -file -recurse | Foreach-Object {Write-Host $_.FullName.length, $_.FullName}

Open in new window

Avatar of AlHal2

ASKER

This is the longest path I could find.  It's only 231 characters.

D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin\QAForumSolution\packages\Microsoft.ApplicationInsights.PerfCounterCollector.2.2.0\Microsoft.ApplicationInsights.PerfCounterCollector.2.2.0.nupkg

I used this code to find it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

                foreach (string path in Directory.EnumerateFiles(@"D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin", "*.*", SearchOption.AllDirectories))
                {
                    if (File.Exists(path))
                    {
                        // This path is a file
                        ProcessFile(path);
                    }
                    else if (Directory.Exists(path))
                    {
                        // This path is a directory
                        ProcessDirectory(path);
                    }
                    else
                    {
                        Console.WriteLine("{0} is not a valid file or directory.", path);
                    }
                }
            
        }
        public void ProcessDirectory(string targetDirectory)
        {
            // Process the list of files found in the directory.
            string[] fileEntries = Directory.GetFiles(targetDirectory);
            foreach (string fileName in fileEntries)
                ProcessFile(fileName);

            // Recurse into subdirectories of this directory.
            string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
            foreach (string subdirectory in subdirectoryEntries)
                ProcessDirectory(subdirectory);
        }

        // Insert logic for processing found files here.
       public void ProcessFile(string path)
        {
            using (StreamWriter sw = new StreamWriter(@"D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin\Results.csv",true))
            {
                sw.WriteLine(path.Length + "," + path);
            }
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2

ASKER

192 characters
C:\Users\ahalp\source\repos\QAForumSolution\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0.nupkg

Using the previous file structure 252 characters
D:\OneDrive\Documents\Courses\QAASPNETMVC\Labs\04  DataStorage\01 Setup Projects\Begin\QAForumSolution\packages\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0\Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.2.2.0.nupkg

Thanks everyone.  I know 252 is less than 260, but I think the point is made.