Sideway
output.to from Sideway
Draft for Information Only

Content

Path
 Path Class
  Fields
  Methods
  Remarks
  Applies to
  See also
 PathTooLongException
  Constructors
  Properties
  Methods
  Events
  Remarks
  Applies to
  See also
 Source/Reference

Path

The path components used in .NET framework is Path, and PathTooLongException.

Path Class

Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.

NamespaceSystem.IO AssembliesSystem.Runtime.Extensions.dll, mscorlib.dll, netstandard.dll
[System.Runtime.InteropServices.ComVisible(true)]
public static class Path

Inheritance: Object->Path

Attributes: ComVisibleAttribute

Fields

AltDirectorySeparatorChar

Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.

DirectorySeparatorChar

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

InvalidPathChars

Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the Path class.

PathSeparator

A platform-specific separator character used to separate path strings in environment variables.

VolumeSeparatorChar

Provides a platform-specific volume separator character.

Methods

ChangeExtension(String, String)

Changes the extension of a path string.

Combine(String[])

Combines an array of strings into a path.

Combine(String, String)

Combines two strings into a path.

Combine(String, String, String)

Combines three strings into a path.

Combine(String, String, String, String)

Combines four strings into a path.

GetDirectoryName(String)

Returns the directory information for the specified path string.

GetExtension(String)

Returns the extension (including the period ".") of the specified path string.

GetFileName(String)

Returns the file name and extension of the specified path string.

GetFileNameWithoutExtension(String)

Returns the file name of the specified path string without the extension.

GetFullPath(String)

Returns the absolute path for the specified path string.

GetInvalidFileNameChars()

Gets an array containing the characters that are not allowed in file names.

GetInvalidPathChars()

Gets an array containing the characters that are not allowed in path names.

GetPathRoot(String)

Gets the root directory information of the specified path.

GetRandomFileName()

Returns a random folder name or file name.

GetTempFileName()

Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

GetTempPath()

Returns the path of the current user's temporary folder.

HasExtension(String)

Determines whether a path includes a file name extension.

IsPathRooted(String)

Returns a value indicating whether the specified path string contains a root.

Remarks

  • A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform. For example, on some systems, a path can start with a drive or volume letter, while this element is not present in other systems. On some systems, file paths can contain extensions, which indicate the type of information stored in the file. The format of a file name extension is platform-dependent; for example, some systems limit extensions to three characters, and others do not. The current platform also determines the set of characters used to separate the elements of a path, and the set of characters that cannot be used when specifying paths. Because of these differences, the fields of the Path class as well as the exact behavior of some members of the Path class are platform-dependent.

    A path can contain absolute or relative location information. Absolute paths fully specify a location: the file or directory can be uniquely identified regardless of the current location. Relative paths specify a partial location: the current location is used as the starting point when locating a file specified with a relative path. To determine the current directory, call Directory.GetCurrentDirectory.

    .NET Core 1.1 and later versions and .NET Framework 4.6.2 and later versions also support access to file system objects that are device names, such as "\?\C:".

    For more information on file path formats on Windows, see File path formats on Windows systems.

    Most members of the Path class do not interact with the file system and do not verify the existence of the file specified by a path string. Path class members that modify a path string, such as ChangeExtension, have no effect on names of files in the file system. Path members do, however, validate the contents of a specified path string, and throw an ArgumentException exception if the string contains characters that are not valid in path strings, as defined in the characters returned from the GetInvalidPathChars method. For example, on Windows-based desktop platforms, invalid path characters might include quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0), and Unicode characters 16 through 18 and 20 through 25.

    The members of the Path class enable you to quickly and easily perform common operations such as determining whether a file name extension is part of a path, and combining two strings into one path name.

    All members of the Path class are static and can therefore be called without having an instance of a path.

    Note

    In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.

    In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:

    • "c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.

    • "c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.

    • "MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.

    • "\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.

    Because all these operations are performed on strings, it is impossible to verify that the results are valid in all scenarios. For example, the GetExtension method parses a string that you pass to it and returns the extension from that string. However, this does not mean that a file with that extension exists on the disk.

    For a list of common I/O tasks, see Common I/O Tasks.

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

PathTooLongException

The exception that is thrown when a path or fully qualified file name is longer than the system-defined maximum length.

NamespaceSystem.IO AssembliesSystem.Runtime.dll, mscorlib.dll, netstandard.dll
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class PathTooLongException : System.IO.IOException

Inheritance: Object->Exception->SystemException->IOException->PathTooLongException

Attributes: ComVisibleAttribute, SerializableAttribute

Constructors

PathTooLongException()

Initializes a new instance of the PathTooLongException class with its HRESULT set to COR_E_PATHTOOLONG.

PathTooLongException(SerializationInfo, StreamingContext)

Initializes a new instance of the PathTooLongException class with the specified serialization and context information.

PathTooLongException(String)

Initializes a new instance of the PathTooLongException class with its message string set to message and its HRESULT set to COR_E_PATHTOOLONG.

PathTooLongException(String, Exception)

Initializes a new instance of the PathTooLongException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Properties

Data

Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink

Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult

Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException

Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message

Gets a message that describes the current exception.

(Inherited from Exception)
Source

Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace

Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite

Gets the method that throws the current exception.

(Inherited from Exception)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException()

When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)

When overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType()

Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Creates and returns a string representation of the current exception.

(Inherited from Exception)

Events

SerializeObjectState

Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Remarks

  • If your code does not have FileIOPermissionAttribute.PathDiscovery permission, the error message for this exception may contain only file or directory names instead of full paths.

    In apps that run under versions of the .NET Framework prior to the .NET Framework 4.6.2, full paths must not exceed 260 characters to maintain compatibility with Windows operating systems. Any path in excess of 260 characters automatically throws a PathTooLongException. For more information about this restriction, see the entry Long Paths in .NET in the BCL Team blog.

    Note

    This exception is not included in .NET for Windows Store apps or the Portable Class Library, but it is thrown by some members that are. To catch the exception in that case, write a catch statement that handles an IOException instead.

    Starting with apps running under the .NET Framework 4.6.2, the .NET Framework supports long paths in excess of 260 (or MAX_PATH) characters. The conditions under which a PathTooLongException exception are thrown depend on the version of the .NET Framework that an app targets:

    Apps that target the .NET Framework 4.6.2 and later versions
    Long paths are supported by default. The runtime throws a PathTooLongException under the following conditions:

    • The operating system returns COR_E_PATHTOOLONG or its equivalent.

    • The length of the path exceeds Int16.MaxValue (32,767) characters.

    Apps that target the .NET Framework 4.6.1 and earlier versions
    Long paths are disabled by default, and the legacy behavior is maintained. The runtime throws a PathTooLongException whenever a path exceeds 260 characters.

    If this is undesirable, apps that target the .NET Framework 4.6.1 and earlier but run under the .NET Framework 4.6.2 can enable long path support by including the following setting in the <runtime> element of the application configuration file:

    XML
    
    <runtime>   
       <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />   
    </runtime>  
    

    PathTooLongException uses the HRESULT COR_E_PATHTOOLONG, which has the value 0x800700CE.

Applies to

.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

See also

Source/Reference


©sideway

ID: 200700018 Last Updated: 7/18/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019