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
- DecoderReplacementFallback.cs
- HttpRuntime.cs
- AuthenticationConfig.cs
- ObjectDataSourceMethodEventArgs.cs
- EventLogEntryCollection.cs
- XmlAnyElementAttribute.cs
- CodeStatementCollection.cs
- CompositeControl.cs
- UserControlParser.cs
- SendKeys.cs
- MenuAdapter.cs
- EventLogPermissionAttribute.cs
- SimpleRecyclingCache.cs
- SqlGenericUtil.cs
- RC2.cs
- LineServices.cs
- Environment.cs
- TemplateLookupAction.cs
- StatusStrip.cs
- SoapAttributeAttribute.cs
- SrgsGrammarCompiler.cs
- MemberHolder.cs
- StreamHelper.cs
- ImageAttributes.cs
- HtmlInputCheckBox.cs
- BooleanAnimationUsingKeyFrames.cs
- _ListenerAsyncResult.cs
- SqlError.cs
- PageCatalogPart.cs
- FocusTracker.cs
- Psha1DerivedKeyGeneratorHelper.cs
- RadioButton.cs
- TiffBitmapEncoder.cs
- IconConverter.cs
- SecurityDocument.cs
- CancellationHandlerDesigner.cs
- DataGridViewColumnHeaderCell.cs
- ClientRuntimeConfig.cs
- InputGestureCollection.cs
- AuthorizationRuleCollection.cs
- HtmlButton.cs
- PageEventArgs.cs
- SafeEventLogReadHandle.cs
- MatrixAnimationUsingPath.cs
- Trace.cs
- MatrixCamera.cs
- PeerTransportCredentialType.cs
- Positioning.cs
- TablePattern.cs
- FilterQuery.cs
- safex509handles.cs
- HtmlImage.cs
- Int32AnimationUsingKeyFrames.cs
- StringAnimationBase.cs
- util.cs
- PageBreakRecord.cs
- TableItemStyle.cs
- CodeGen.cs
- TrackingDataItem.cs
- RowVisual.cs
- WeakReferenceKey.cs
- InkCanvasFeedbackAdorner.cs
- ParameterCollection.cs
- Int64Converter.cs
- MediaEntryAttribute.cs
- ServiceBehaviorAttribute.cs
- TogglePatternIdentifiers.cs
- CompilerGeneratedAttribute.cs
- CngAlgorithmGroup.cs
- DbParameterHelper.cs
- TypeBrowser.xaml.cs
- BrowserCapabilitiesCodeGenerator.cs
- MetaModel.cs
- ReachDocumentPageSerializer.cs
- DataReaderContainer.cs
- X500Name.cs
- ControlBuilderAttribute.cs
- TdsParserSafeHandles.cs
- TransportDefaults.cs
- TreeNodeBindingCollection.cs
- BrowserDefinition.cs
- StreamMarshaler.cs
- SspiNegotiationTokenAuthenticator.cs
- ResourceDescriptionAttribute.cs
- SessionPageStatePersister.cs
- WorkflowInstanceTerminatedRecord.cs
- FixedTextSelectionProcessor.cs
- PageRanges.cs
- FrameworkRichTextComposition.cs
- SpanIndex.cs
- TextDecorationCollection.cs
- CornerRadius.cs
- ApplicationInterop.cs
- AtomServiceDocumentSerializer.cs
- ListDataBindEventArgs.cs
- HttpContextBase.cs
- Configuration.cs
- MimeFormatExtensions.cs
- CollectionConverter.cs
- AutomationProperties.cs