Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- DatePicker.cs
- SByte.cs
- DrawingImage.cs
- BaseParaClient.cs
- ArrayWithOffset.cs
- TaskFileService.cs
- BitmapEffectCollection.cs
- BoundField.cs
- ColorIndependentAnimationStorage.cs
- SqlMethods.cs
- BridgeDataReader.cs
- DomNameTable.cs
- activationcontext.cs
- JpegBitmapDecoder.cs
- WaitHandle.cs
- FilteredDataSetHelper.cs
- CodeMemberProperty.cs
- SmiEventSink.cs
- LicenseContext.cs
- Pkcs7Recipient.cs
- DesignerFrame.cs
- XamlPathDataSerializer.cs
- DebugHandleTracker.cs
- Stroke2.cs
- FixedDSBuilder.cs
- DocumentPageViewAutomationPeer.cs
- ValidationContext.cs
- DispatcherSynchronizationContext.cs
- DataPagerCommandEventArgs.cs
- ActivationArguments.cs
- CompilerCollection.cs
- SystemTcpStatistics.cs
- WebPartDeleteVerb.cs
- SocketPermission.cs
- VisualCollection.cs
- SplitterPanel.cs
- TextDecorationCollection.cs
- SamlAttributeStatement.cs
- ExternalCalls.cs
- CommonProperties.cs
- ProtectedConfiguration.cs
- Trace.cs
- NextPreviousPagerField.cs
- DuplicateDetector.cs
- UserPreferenceChangingEventArgs.cs
- RandomDelayQueuedSendsAsyncResult.cs
- Transform.cs
- XmlProcessingInstruction.cs
- EntityWithChangeTrackerStrategy.cs
- Peer.cs
- XmlSchemaSimpleTypeUnion.cs
- FileDataSourceCache.cs
- ControlPropertyNameConverter.cs
- Math.cs
- PrinterSettings.cs
- CompilerTypeWithParams.cs
- FormView.cs
- TraceLevelStore.cs
- HtmlElement.cs
- ActivityLocationReferenceEnvironment.cs
- XmlSchemaValidationException.cs
- SectionInformation.cs
- DescendantQuery.cs
- PatternMatcher.cs
- UIElementCollection.cs
- ItemsPanelTemplate.cs
- Int16.cs
- ZipPackagePart.cs
- WebDisplayNameAttribute.cs
- EdmError.cs
- SystemMulticastIPAddressInformation.cs
- X509CertificateEndpointIdentity.cs
- UmAlQuraCalendar.cs
- ChildTable.cs
- IndexedString.cs
- OracleConnectionFactory.cs
- LogicalExpr.cs
- Timer.cs
- MemoryMappedView.cs
- XmlSchemaSequence.cs
- ImpersonationContext.cs
- InteropAutomationProvider.cs
- ScrollChangedEventArgs.cs
- PaintValueEventArgs.cs
- ControlBuilder.cs
- VolatileEnlistmentMultiplexing.cs
- ThreadNeutralSemaphore.cs
- NullableConverter.cs
- ZipIOLocalFileBlock.cs
- DataSetUtil.cs
- NumberFormatter.cs
- ZoneButton.cs
- ReachPrintTicketSerializerAsync.cs
- CloudCollection.cs
- PreservationFileWriter.cs
- TypeUnloadedException.cs
- GenericTypeParameterBuilder.cs
- CompilerError.cs
- TableAutomationPeer.cs
- FocusChangedEventArgs.cs