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
- CompositeCollection.cs
- CapabilitiesPattern.cs
- ListViewTableCell.cs
- MessageSecurityOverTcpElement.cs
- SqlSelectStatement.cs
- FloaterParagraph.cs
- SqlCacheDependencyDatabase.cs
- XmlSchema.cs
- DetailsView.cs
- XmlChoiceIdentifierAttribute.cs
- TextEditorCopyPaste.cs
- DynamicILGenerator.cs
- webeventbuffer.cs
- AudioLevelUpdatedEventArgs.cs
- InlineObject.cs
- Tokenizer.cs
- NotifyIcon.cs
- XmlSchemaInferenceException.cs
- RequestNavigateEventArgs.cs
- BufferedGraphicsManager.cs
- ExtenderHelpers.cs
- ProcessHostFactoryHelper.cs
- StringComparer.cs
- UInt16.cs
- BufferedStream2.cs
- TemplateBamlRecordReader.cs
- ServerType.cs
- EpmContentSerializer.cs
- DeflateEmulationStream.cs
- SamlAction.cs
- RawStylusInputReport.cs
- BindingsCollection.cs
- EntityException.cs
- BindingListCollectionView.cs
- IntegerValidatorAttribute.cs
- CommandConverter.cs
- DoubleCollectionValueSerializer.cs
- SystemColorTracker.cs
- BadImageFormatException.cs
- Boolean.cs
- GlyphRunDrawing.cs
- DesignerVerbCollection.cs
- EntityTypeEmitter.cs
- WSTrustDec2005.cs
- ObjectStorage.cs
- AsyncResult.cs
- SHA1CryptoServiceProvider.cs
- ValidatorCollection.cs
- Trigger.cs
- EventMappingSettingsCollection.cs
- mediapermission.cs
- COM2Properties.cs
- EntryPointNotFoundException.cs
- UserControl.cs
- ResponseBodyWriter.cs
- EditorBrowsableAttribute.cs
- ProviderSettings.cs
- DecimalAnimation.cs
- Context.cs
- SqlConnectionPoolProviderInfo.cs
- IpcPort.cs
- WebPartZoneCollection.cs
- sqlmetadatafactory.cs
- DelimitedListTraceListener.cs
- ExtensionQuery.cs
- PropertyTabAttribute.cs
- AnyReturnReader.cs
- SystemIPGlobalProperties.cs
- DropShadowEffect.cs
- IndividualDeviceConfig.cs
- TracedNativeMethods.cs
- DoubleAnimationBase.cs
- InputProcessorProfiles.cs
- DataGridPagerStyle.cs
- HttpListener.cs
- QueryCursorEventArgs.cs
- XNodeSchemaApplier.cs
- LocatorManager.cs
- WindowsGraphics2.cs
- Compiler.cs
- ColorConvertedBitmap.cs
- InputLangChangeEvent.cs
- DrawingContextDrawingContextWalker.cs
- StorageMappingItemLoader.cs
- FolderLevelBuildProvider.cs
- RuleConditionDialog.Designer.cs
- _CommandStream.cs
- GroupItemAutomationPeer.cs
- PolyLineSegmentFigureLogic.cs
- KerberosSecurityTokenAuthenticator.cs
- StringToken.cs
- FixUp.cs
- WMIGenerator.cs
- MemberAssignmentAnalysis.cs
- CustomValidator.cs
- EndpointBehaviorElement.cs
- LinkLabelLinkClickedEvent.cs
- SqlConnectionHelper.cs
- InstancePersistenceEvent.cs
- XamlTreeBuilderBamlRecordWriter.cs