2

Possible Duplicate:
How to avoid System.IO.PathTooLongException?

In my application folder structure has a very long time. I need the files saved in this folder (I have no option to change the schema folder!)

[Edited]

using (var fileStream = File.Create(@"\\?\" + filePath, (int) file.Value.Length))
{
    var bytesInStream = new byte[file.Value.Length];
    file.Value.Read(bytesInStream, 0, bytesInStream.Length);
    fileStream.Write(bytesInStream, 0, bytesInStream.Length);
}

The problem is that the full path "filePath" has more than 260 characters!

Error:

System.IO.PathTooLongException 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.

But he must be saved in this folder!

How, without changing the folder structure or file name, I can save this file in this folder?

Community
  • 1
  • 1
ridermansb
  • 10,779
  • 24
  • 115
  • 226
  • Can you refer to the files by their DOS shortened names? AKA `Documents and Settings` can typically be be shorted to `DOCUMEN~1` or something. – Tejs May 11 '12 at 15:49
  • I modified the code to: `using (var fileStream = File.Create(@"\\?\" + filePath, (int) file.Value.Length))` But the same error occurs! – ridermansb May 11 '12 at 16:48
  • Why do you need such long filenames? – Darin Dimitrov May 11 '12 at 16:54
  • I do not need file name logos. The problem is that the full path is long! "\\?\C:\Users\Riderman_2\Work\datafilme\src\DataFilme\DataFilme\App_Files\Produtos\118dc343-0025-4016-c92a-48d02165d699\Visoes\861c9831-f8ce-7946-9e9e-702cdc9d99ca\Valores\32ed0254-77be-0d59-a995-65be34749991\ISIS para configuração de digitalizadores da série i920.pdf" > Folder Product > {'Product ID'}> Folder View> {'id view'}> Folder View Item> {'ID view item'}> Archives – ridermansb May 11 '12 at 17:02

1 Answers1

2

Great article about using long paths and the headaches involved. Ensure you ACTUALLY need them before heading down this path. Relative paths don't working "...\a.txt"

http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx

Other alternatives are to use the Win32 API to make your calls directly.

Oblivion2000
  • 616
  • 4
  • 9
  • I've read this article! And several other related =)! I can not change the folder structure or even the file name! I really need to create files in a folder structure long! – ridermansb May 11 '12 at 17:04