1

I have a shared folder @"\Machine Name\Venkatesh\test" and which contains a file name.

and I want to copy that file into C:\temp\Mani\1.pdf.

I tried the following C# Code but it throws an Exception,

        string sourcepath =   @"\\Venki\Venkatesh\test";
        string destFileName = @"C:\temp\Mani\1.pdf";

        try
        {
            string[] files = Directory.GetFiles(sourcepath);
            foreach (string file in files)
            {
                Console.WriteLine(file.Length);
                File.Copy(file, destFileName);
                Console.WriteLine("Success");
                Console.WriteLine("Done");

            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }

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. Kindly help me with this.

Thanks in advance.

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
  • What are you hoping for? Your filename is too long. The fully qualified file name is 264 characters long. Thus, `PathTooLongException`. For alternative solutions, search for other questions that have answered this multiple times. – Tyler Lee Nov 25 '15 at 07:45
  • I tried with Prefixing the path with "\\?\" then also same exception. – Venkatesh Venky Nov 25 '15 at 07:48

0 Answers0