Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / IO / FileSystemInfo.cs / 1305376 / FileSystemInfo.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: FileSystemInfo ** **[....] ** ** ** Purpose: ** ** ===========================================================*/ using System; using System.Collections; using System.Security; using System.Security.Permissions; using Microsoft.Win32; using System.Text; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Diagnostics.Contracts; namespace System.IO { [Serializable] [FileIOPermissionAttribute(SecurityAction.InheritanceDemand,Unrestricted=true)] [ComVisible(true)] #if FEATURE_REMOTING public abstract class FileSystemInfo : MarshalByRefObject, ISerializable { #if false } #endif //false #else // FEATURE_REMOTING public abstract class FileSystemInfo : ISerializable { #endif //FEATURE_REMOTING [System.Security.SecurityCritical /*auto-generated*/] internal Win32Native.WIN32_FILE_ATTRIBUTE_DATA _data; // Cache the file information internal int _dataInitialised = -1; // We use this field in conjunction with the Refresh methods, if we succeed // we store a zero, on failure we store the HResult in it so that we can // give back a generic error back. private const int ERROR_INVALID_PARAMETER = 87; internal const int ERROR_ACCESS_DENIED = 0x5; protected String FullPath; // fully qualified path of the directory protected String OriginalPath; // path passed in by the user private String _displayPath = ""; // path that can be displayed to the user protected FileSystemInfo() { } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] protected FileSystemInfo(SerializationInfo info, StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); Contract.EndContractBlock(); // Must use V1 field names here, since V1 didn't implement // ISerializable. FullPath = Path.GetFullPathInternal(info.GetString("FullPath")); OriginalPath = info.GetString("OriginalPath"); // Lazily initialize the file attributes. _dataInitialised = -1; } [System.Security.SecurityCritical] internal void InitializeFrom(Win32Native.WIN32_FIND_DATA findData) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); _data.PopulateFrom(findData); _dataInitialised = 0; } // Full path of the direcory/file public virtual String FullName { [System.Security.SecuritySafeCritical] // auto-generated get { String demandDir; if (this is DirectoryInfo) demandDir = Directory.GetDemandDir(FullPath, true); else demandDir = FullPath; new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandDir).Demand(); return FullPath; } } public String Extension { get { // GetFullPathInternal would have already stripped out the terminating "." if present. int length = FullPath.Length; for (int i = length; --i >= 0;) { char ch = FullPath[i]; if (ch == '.') return FullPath.Substring(i, length - i); if (ch == Path.DirectorySeparatorChar || ch == Path.AltDirectorySeparatorChar || ch == Path.VolumeSeparatorChar) break; } return String.Empty; } } // For files name of the file is returned, for directories the last directory in hierarchy is returned if possible, // otherwise the fully qualified name s returned public abstract String Name { get; } // Whether a file/directory exists public abstract bool Exists { get; } // Delete a file/directory public abstract void Delete(); public DateTime CreationTime { [System.Security.SecuritySafeCritical] // auto-generated get { return CreationTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { CreationTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime CreationTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftCreationTimeHigh << 32) | _data.ftCreationTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetCreationTimeUtc(FullPath,value); else File.SetCreationTimeUtc(FullPath,value); _dataInitialised = -1; } } public DateTime LastAccessTime { [System.Security.SecuritySafeCritical] // auto-generated get { return LastAccessTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { LastAccessTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime LastAccessTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftLastAccessTimeHigh << 32) | _data.ftLastAccessTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetLastAccessTimeUtc(FullPath,value); else File.SetLastAccessTimeUtc(FullPath,value); _dataInitialised = -1; } } public DateTime LastWriteTime { [System.Security.SecuritySafeCritical] // auto-generated get { return LastWriteTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { LastWriteTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime LastWriteTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftLastWriteTimeHigh << 32) | _data.ftLastWriteTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetLastWriteTimeUtc(FullPath,value); else File.SetLastWriteTimeUtc(FullPath,value); _dataInitialised = -1; } } [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] public void Refresh() { _dataInitialised = File.FillAttributeInfo(FullPath, ref _data, false, false); } public FileAttributes Attributes { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); // Call refresh to intialise the data } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); return (FileAttributes) _data.fileAttributes; } [System.Security.SecuritySafeCritical] // auto-generated set { new FileIOPermission(FileIOPermissionAccess.Write, FullPath).Demand(); bool r = Win32Native.SetFileAttributes(FullPath, (int) value); if (!r) { int hr = Marshal.GetLastWin32Error(); if (hr==ERROR_INVALID_PARAMETER) throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileAttrs")); // For whatever reason we are turning ERROR_ACCESS_DENIED into // ArgumentException here (probably done for some 9x code path). // We can't change this now but special casing the error message instead. if (hr == ERROR_ACCESS_DENIED) throw new ArgumentException(Environment.GetResourceString("UnauthorizedAccess_IODenied_NoPathName")); __Error.WinIOError(hr, DisplayPath); } _dataInitialised = -1; } } [System.Security.SecurityCritical] // auto-generated_required [ComVisible(false)] public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, FullPath).Demand(); info.AddValue("OriginalPath", OriginalPath, typeof(String)); info.AddValue("FullPath", FullPath, typeof(String)); } internal String DisplayPath { get { return _displayPath; } set { _displayPath = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: FileSystemInfo ** **[....] ** ** ** Purpose: ** ** ===========================================================*/ using System; using System.Collections; using System.Security; using System.Security.Permissions; using Microsoft.Win32; using System.Text; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Diagnostics.Contracts; namespace System.IO { [Serializable] [FileIOPermissionAttribute(SecurityAction.InheritanceDemand,Unrestricted=true)] [ComVisible(true)] #if FEATURE_REMOTING public abstract class FileSystemInfo : MarshalByRefObject, ISerializable { #if false } #endif //false #else // FEATURE_REMOTING public abstract class FileSystemInfo : ISerializable { #endif //FEATURE_REMOTING [System.Security.SecurityCritical /*auto-generated*/] internal Win32Native.WIN32_FILE_ATTRIBUTE_DATA _data; // Cache the file information internal int _dataInitialised = -1; // We use this field in conjunction with the Refresh methods, if we succeed // we store a zero, on failure we store the HResult in it so that we can // give back a generic error back. private const int ERROR_INVALID_PARAMETER = 87; internal const int ERROR_ACCESS_DENIED = 0x5; protected String FullPath; // fully qualified path of the directory protected String OriginalPath; // path passed in by the user private String _displayPath = ""; // path that can be displayed to the user protected FileSystemInfo() { } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] protected FileSystemInfo(SerializationInfo info, StreamingContext context) { if (info == null) throw new ArgumentNullException("info"); Contract.EndContractBlock(); // Must use V1 field names here, since V1 didn't implement // ISerializable. FullPath = Path.GetFullPathInternal(info.GetString("FullPath")); OriginalPath = info.GetString("OriginalPath"); // Lazily initialize the file attributes. _dataInitialised = -1; } [System.Security.SecurityCritical] internal void InitializeFrom(Win32Native.WIN32_FIND_DATA findData) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); _data.PopulateFrom(findData); _dataInitialised = 0; } // Full path of the direcory/file public virtual String FullName { [System.Security.SecuritySafeCritical] // auto-generated get { String demandDir; if (this is DirectoryInfo) demandDir = Directory.GetDemandDir(FullPath, true); else demandDir = FullPath; new FileIOPermission(FileIOPermissionAccess.PathDiscovery, demandDir).Demand(); return FullPath; } } public String Extension { get { // GetFullPathInternal would have already stripped out the terminating "." if present. int length = FullPath.Length; for (int i = length; --i >= 0;) { char ch = FullPath[i]; if (ch == '.') return FullPath.Substring(i, length - i); if (ch == Path.DirectorySeparatorChar || ch == Path.AltDirectorySeparatorChar || ch == Path.VolumeSeparatorChar) break; } return String.Empty; } } // For files name of the file is returned, for directories the last directory in hierarchy is returned if possible, // otherwise the fully qualified name s returned public abstract String Name { get; } // Whether a file/directory exists public abstract bool Exists { get; } // Delete a file/directory public abstract void Delete(); public DateTime CreationTime { [System.Security.SecuritySafeCritical] // auto-generated get { return CreationTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { CreationTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime CreationTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftCreationTimeHigh << 32) | _data.ftCreationTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetCreationTimeUtc(FullPath,value); else File.SetCreationTimeUtc(FullPath,value); _dataInitialised = -1; } } public DateTime LastAccessTime { [System.Security.SecuritySafeCritical] // auto-generated get { return LastAccessTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { LastAccessTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime LastAccessTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftLastAccessTimeHigh << 32) | _data.ftLastAccessTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetLastAccessTimeUtc(FullPath,value); else File.SetLastAccessTimeUtc(FullPath,value); _dataInitialised = -1; } } public DateTime LastWriteTime { [System.Security.SecuritySafeCritical] // auto-generated get { return LastWriteTimeUtc.ToLocalTime(); } #if FEATURE_CORECLR //Need the getter to be public and the setter to be internal: TrimSrc doesn't parse into property declarations internal #endif //FEATURE_CORECLR set { LastWriteTimeUtc = value.ToUniversalTime(); } } [ComVisible(false)] public DateTime LastWriteTimeUtc { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); long fileTime = ((long)_data.ftLastWriteTimeHigh << 32) | _data.ftLastWriteTimeLow; return DateTime.FromFileTimeUtc(fileTime); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] set { if (this is DirectoryInfo) Directory.SetLastWriteTimeUtc(FullPath,value); else File.SetLastWriteTimeUtc(FullPath,value); _dataInitialised = -1; } } [System.Security.SecuritySafeCritical] // auto-generated [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] public void Refresh() { _dataInitialised = File.FillAttributeInfo(FullPath, ref _data, false, false); } public FileAttributes Attributes { [System.Security.SecuritySafeCritical] // auto-generated get { if (_dataInitialised == -1) { _data = new Win32Native.WIN32_FILE_ATTRIBUTE_DATA(); Refresh(); // Call refresh to intialise the data } if (_dataInitialised != 0) // Refresh was unable to initialise the data __Error.WinIOError(_dataInitialised, DisplayPath); return (FileAttributes) _data.fileAttributes; } [System.Security.SecuritySafeCritical] // auto-generated set { new FileIOPermission(FileIOPermissionAccess.Write, FullPath).Demand(); bool r = Win32Native.SetFileAttributes(FullPath, (int) value); if (!r) { int hr = Marshal.GetLastWin32Error(); if (hr==ERROR_INVALID_PARAMETER) throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileAttrs")); // For whatever reason we are turning ERROR_ACCESS_DENIED into // ArgumentException here (probably done for some 9x code path). // We can't change this now but special casing the error message instead. if (hr == ERROR_ACCESS_DENIED) throw new ArgumentException(Environment.GetResourceString("UnauthorizedAccess_IODenied_NoPathName")); __Error.WinIOError(hr, DisplayPath); } _dataInitialised = -1; } } [System.Security.SecurityCritical] // auto-generated_required [ComVisible(false)] public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { new FileIOPermission(FileIOPermissionAccess.PathDiscovery, FullPath).Demand(); info.AddValue("OriginalPath", OriginalPath, typeof(String)); info.AddValue("FullPath", FullPath, typeof(String)); } internal String DisplayPath { get { return _displayPath; } set { _displayPath = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ArrayElementGridEntry.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- FontDifferentiator.cs
- arabicshape.cs
- validationstate.cs
- ToolStripLocationCancelEventArgs.cs
- ToolboxComponentsCreatedEventArgs.cs
- MimeReflector.cs
- XmlStreamStore.cs
- FlowPosition.cs
- TableLayoutRowStyleCollection.cs
- HitTestResult.cs
- MarkupCompilePass2.cs
- TemplateAction.cs
- DetailsViewInsertedEventArgs.cs
- ContractValidationHelper.cs
- TextProviderWrapper.cs
- NetworkStream.cs
- XmlWrappingReader.cs
- XamlReader.cs
- Triplet.cs
- XmlSchemaAnyAttribute.cs
- CompilationRelaxations.cs
- DataServiceException.cs
- CellRelation.cs
- UserControl.cs
- MonthChangedEventArgs.cs
- ValidationError.cs
- SafeMILHandleMemoryPressure.cs
- HtmlTableRowCollection.cs
- LinqDataSourceStatusEventArgs.cs
- CatalogZone.cs
- xmlsaver.cs
- NetworkInformationException.cs
- ClientProxyGenerator.cs
- SqlWriter.cs
- Point4DConverter.cs
- ContentPosition.cs
- _DisconnectOverlappedAsyncResult.cs
- Duration.cs
- MsmqBindingMonitor.cs
- DirectionalLight.cs
- HttpCapabilitiesBase.cs
- WebMessageEncoderFactory.cs
- DeadLetterQueue.cs
- RegisteredArrayDeclaration.cs
- PersonalizableAttribute.cs
- ClientConfigPaths.cs
- ErrorLog.cs
- GridViewHeaderRowPresenter.cs
- formatstringdialog.cs
- StringSorter.cs
- SimpleTextLine.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- Shape.cs
- GridViewUpdatedEventArgs.cs
- TreeBuilderXamlTranslator.cs
- PluralizationService.cs
- ResourceSet.cs
- ListSortDescription.cs
- InputProcessorProfilesLoader.cs
- CanonicalXml.cs
- StreamWriter.cs
- SortExpressionBuilder.cs
- ProgressBarRenderer.cs
- RealProxy.cs
- PermissionSet.cs
- Brush.cs
- IOException.cs
- IEnumerable.cs
- GroupItem.cs
- XmlDataSourceView.cs
- IntSecurity.cs
- FormsAuthenticationTicket.cs
- ColumnResult.cs
- GridViewSortEventArgs.cs
- DotAtomReader.cs
- TypeBuilderInstantiation.cs
- InProcStateClientManager.cs
- HttpAsyncResult.cs
- Encoder.cs
- NavigationService.cs
- serverconfig.cs
- HttpHandlersSection.cs
- ThreadTrace.cs
- ConstraintCollection.cs
- NavigationWindowAutomationPeer.cs
- BlockCollection.cs
- EdmEntityTypeAttribute.cs
- IdentityManager.cs
- SqlFacetAttribute.cs
- StreamUpdate.cs
- XmlIlVisitor.cs
- AppDomain.cs
- BindingCompleteEventArgs.cs
- LogicalExpr.cs
- BlurBitmapEffect.cs
- EventSinkActivity.cs
- Executor.cs
- SymbolDocumentInfo.cs