c# - Best way to resolve file path too long exception -


I have created an app that downloads all the document libraries in SP site, but at one point it is giving me this error (I tried but did not find anything by looking at Google, now if anyone knows any tricks to solve this problem, please thank me otherwise to see it)

System .IO.PathTooLongException: The specified path, file name, or both are too long to be fully qualified Ail name must be less than 260 characters, and the directory name must be less than 248 characters. System.IO.FileStream.Init on System.IO.Path.NormalizePathFast (string path, boolean fullCheck) on system.IO.Path.GetFullPathInternal (string path) (string path, FileMode mode, FileAccess access, Int32 rights, boolean useRights On, fileshare share, int32 bufferSize, FileOptions option, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) on System.IO.FileStream..ctor (in system string path, FileMode mode, FileAccess usage, fileshare share, Int32 bufferSize, FileOptions option ). IO.File.Create (String Path)

It reaches the limit for the string, code is given below,

  #region Downloading schemes private Zero btnDownload_Click (object sender, event ergues e) {tree node current node = t webbs Selected node; SPObjectData objectData = (SPObjectData) currentNode.Tag; Try {CreateLoggingFile (); (SPWeb is using TopLevelWeb = objectData.Web) {if (TopLevelWeb! = Null) dwnEachWeb (TopLevelWeb, TopLevelWeb.Title, tbDirectory.Text); }} Hold (exception before) {Tres. WriteLine (string.Format ("exception") when trying to pass TopLevelWeb: {1}, title = {2}, object data (dwnEachWeb_method), exception: {0} ", Pre. Ostring (), objectadata web, objectData.Title)); } Finally {CloseLoggingFile (); }} Private Zero dwnEachWeb (SPWeb TopLevelWeb, String FolderName, String CurrentDirectory) {if (TopLevelWeb = Null!) {If (TopLevelWeb.Webs = Null!) {CurrentDirectory = CurrentDirectory + "\\" + TopLevelWeb.Title; CreateFolder (CurrentDirectory); Foreign exchange (WebWeb Web Web site) [WEEEABBB (ChildWeb, ChildWeb. Title, Current Directory); ChildWeb.Dispose (); } DwnEachList (TopLevelWeb, Current Directory); // dwnEachList (TopLevelWeb, folder name, current directory); }}} Private Zero dwnEachList (SPWeb oWeb, String CurrentDirectory) {foreach (SPList oList in oWeb.Lists) {if (oList SPDocumentLibrary & amp; OList.Hidden) {dwnEachFile (oList.RootFolder, CurrentDirectory); }}} Private Wide DAEFFile (SP Folder Offolder, String Current Directory) {If (Offloader.file.ccount! = 0) {Current Directory = Current Directory → "\\" + Default. Name; CreateFolder (CurrentDirectory); Forex currency (in the default.file.php file) {if (create directory structure (current directory, oilil. URL)) {var file path = system.io.path. Cobain (current directory, offline. Url); Byte [] binFile = Oylin. OpenBinary (); System.IO.FileStream fstream = System.IO.File.Create (file path); Fstream.Write (binFile, 0, binFile.Length); Fstream.Close (); }}}} To create a directory where files will be downloaded for private child-drawn directory structure (string basefolder, string filepath) {if! (Directory! Axistists) Returned false; Var path = filepath.Split ('/'); For (var i = 0; i & lt; paths.Length - 1; i ++) {baseFolder = System.IO.Path.Combine (basefolder, path [i]); Directory.CreateDirectory (baseFolder); } Back true; } // Create Folders Private Butt CreateFolder (String Current Directory) {if (! Directory.Exists (CurrentDirectory)) {Directory.CreateDirectory (CurrentDirectory); } Back true; } // Shortring String # Without Syrian    

Due to error, it is clear here < / P>

This link is a quote from:

Maximum path length limit in Windows API (with some exceptions discussed in the following paragraph) The maximum length for the path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letters, colon, backslash, separate names component by backslabs, and a nonsensical tap character. For example, the maximum path "D: \ some 256-character path string" on drive D "is & lt; NUL & gt; Where "& lt; NUL & gt;" The current system represents the invisible finished null character for the codepage. (Character & lt;> used for visual clarity and a valid path can not be part of string.)

and some measure (taken from comments):

There are ways to solve various problems The basic idea behind the solutions given below is always the same: path-length + name-length & lt; MAX_PATH .

  • Share a subfolder
  • Use the command line to assign a drive letter
  • Use AddConnection under the VB to assign a drive Letter for path

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -