Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Configuration / System / Configuration / FileUtil.cs / 1 / FileUtil.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.IO; using Microsoft.Win32; using System.Runtime.InteropServices; static internal class FileUtil { const int HRESULT_WIN32_FILE_NOT_FOUND = unchecked((int)0x80070002); const int HRESULT_WIN32_PATH_NOT_FOUND = unchecked((int)0x80070003); // // Use to avoid the perf hit of a Demand when the Demand is not necessary for security. // // If trueOnError is set, then return true if we cannot confirm that the file does NOT exist. // internal static bool FileExists(string filename, bool trueOnError) { UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data; bool ok = UnsafeNativeMethods.GetFileAttributesEx(filename, UnsafeNativeMethods.GetFileExInfoStandard, out data); if (ok) { // The path exists. Return true if it is a file, false if a directory. return (data.fileAttributes & (int) FileAttributes.Directory) != (int) FileAttributes.Directory; } else { if (!trueOnError) { return false; } else { // Return true if we cannot confirm that the file does NOT exist. int hr = Marshal.GetHRForLastWin32Error(); if (hr == HRESULT_WIN32_FILE_NOT_FOUND || hr == HRESULT_WIN32_PATH_NOT_FOUND) { return false; } else { return true; } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.IO; using Microsoft.Win32; using System.Runtime.InteropServices; static internal class FileUtil { const int HRESULT_WIN32_FILE_NOT_FOUND = unchecked((int)0x80070002); const int HRESULT_WIN32_PATH_NOT_FOUND = unchecked((int)0x80070003); // // Use to avoid the perf hit of a Demand when the Demand is not necessary for security. // // If trueOnError is set, then return true if we cannot confirm that the file does NOT exist. // internal static bool FileExists(string filename, bool trueOnError) { UnsafeNativeMethods.WIN32_FILE_ATTRIBUTE_DATA data; bool ok = UnsafeNativeMethods.GetFileAttributesEx(filename, UnsafeNativeMethods.GetFileExInfoStandard, out data); if (ok) { // The path exists. Return true if it is a file, false if a directory. return (data.fileAttributes & (int) FileAttributes.Directory) != (int) FileAttributes.Directory; } else { if (!trueOnError) { return false; } else { // Return true if we cannot confirm that the file does NOT exist. int hr = Marshal.GetHRForLastWin32Error(); if (hr == HRESULT_WIN32_FILE_NOT_FOUND || hr == HRESULT_WIN32_PATH_NOT_FOUND) { return false; } else { return true; } } } } } } // 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
- WpfXamlMember.cs
- diagnosticsswitches.cs
- Merger.cs
- altserialization.cs
- MinimizableAttributeTypeConverter.cs
- DbModificationCommandTree.cs
- SystemFonts.cs
- SqlInternalConnectionTds.cs
- DecoderNLS.cs
- DataPagerFieldCollection.cs
- ViewCellSlot.cs
- BitmapEffectOutputConnector.cs
- TextRunProperties.cs
- DocumentEventArgs.cs
- BindingMAnagerBase.cs
- EventMemberCodeDomSerializer.cs
- SHA256.cs
- XsltException.cs
- LoginName.cs
- AssemblyCollection.cs
- DesignerOptionService.cs
- XmlDataSourceNodeDescriptor.cs
- SafeSecurityHandles.cs
- TypeUtil.cs
- ConfigXmlWhitespace.cs
- Cloud.cs
- DataControlFieldCollection.cs
- BinaryWriter.cs
- CryptoConfig.cs
- ResourceIDHelper.cs
- MaterialGroup.cs
- IsolatedStorageFileStream.cs
- TransformerInfoCollection.cs
- CorrelationRequestContext.cs
- UrlPath.cs
- ToolBarDesigner.cs
- SqlDataSourceStatusEventArgs.cs
- LayoutUtils.cs
- InternalResources.cs
- TreeNodeConverter.cs
- Stacktrace.cs
- FaultImportOptions.cs
- StringFunctions.cs
- NetDataContractSerializer.cs
- MenuItem.cs
- DataGridViewSortCompareEventArgs.cs
- IntPtr.cs
- DesignerActionGlyph.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- DetailsViewActionList.cs
- ServiceModelSecurityTokenTypes.cs
- SelectionRange.cs
- TcpSocketManager.cs
- ItemChangedEventArgs.cs
- WebPartMovingEventArgs.cs
- ReferentialConstraint.cs
- MultipartContentParser.cs
- OleDbRowUpdatingEvent.cs
- Point.cs
- SchemaImporterExtensionElement.cs
- Application.cs
- ControlUtil.cs
- ServiceDescriptionData.cs
- CompilerCollection.cs
- FileClassifier.cs
- RelativeSource.cs
- AuthorizationRuleCollection.cs
- DetailsViewRowCollection.cs
- XmlAttributeCache.cs
- Soap11ServerProtocol.cs
- oledbmetadatacolumnnames.cs
- TypeProvider.cs
- DataQuery.cs
- RowBinding.cs
- DllNotFoundException.cs
- XamlToRtfParser.cs
- PageWrapper.cs
- ShaperBuffers.cs
- InvalidComObjectException.cs
- HttpHeaderCollection.cs
- TdsParser.cs
- ContainerAction.cs
- SqlConnectionPoolProviderInfo.cs
- DataKeyPropertyAttribute.cs
- RawStylusInputCustomData.cs
- basecomparevalidator.cs
- RegisteredDisposeScript.cs
- XmlSchemaSubstitutionGroup.cs
- UpnEndpointIdentityExtension.cs
- GridViewPageEventArgs.cs
- AndCondition.cs
- ExpressionEditorSheet.cs
- ResourceAssociationSetEnd.cs
- Size3D.cs
- SelfIssuedAuthAsymmetricKey.cs
- XmlDataCollection.cs
- SessionPageStateSection.cs
- CharacterHit.cs
- ConfigurationProperty.cs
- webclient.cs