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
- SizeConverter.cs
- NCryptNative.cs
- XsltException.cs
- TransactionFlowAttribute.cs
- CodeSubDirectory.cs
- TrustLevelCollection.cs
- CollectionConverter.cs
- StatusBarItemAutomationPeer.cs
- DownloadProgressEventArgs.cs
- ContextMarshalException.cs
- RSAPKCS1SignatureDeformatter.cs
- WinFormsSecurity.cs
- SmiEventSink_DeferedProcessing.cs
- PageCache.cs
- Classification.cs
- M3DUtil.cs
- ManualResetEvent.cs
- GridLength.cs
- ImageListUtils.cs
- HtmlFormWrapper.cs
- CqlQuery.cs
- Int32.cs
- FormClosedEvent.cs
- BaseWebProxyFinder.cs
- JavaScriptSerializer.cs
- DataListComponentEditor.cs
- HandledMouseEvent.cs
- PersonalizationProviderCollection.cs
- AppDomainProtocolHandler.cs
- FormsAuthenticationCredentials.cs
- ReadContentAsBinaryHelper.cs
- WorkflowControlClient.cs
- ByeOperation11AsyncResult.cs
- RowsCopiedEventArgs.cs
- ActivityExecutionContext.cs
- OrderedDictionaryStateHelper.cs
- SQLGuid.cs
- AutomationPatternInfo.cs
- SrgsOneOf.cs
- HtmlWindow.cs
- XmlFormatExtensionPointAttribute.cs
- AutoGeneratedFieldProperties.cs
- RealizationContext.cs
- FlowLayout.cs
- XamlReader.cs
- PlaceHolder.cs
- ControlEvent.cs
- CodeTypeParameter.cs
- RulePatternOps.cs
- ListViewAutomationPeer.cs
- SynchronizationContext.cs
- ValueTable.cs
- UnicodeEncoding.cs
- Vector3dCollection.cs
- TextBoxAutomationPeer.cs
- NamespaceImport.cs
- RoleManagerModule.cs
- IsolatedStorageFileStream.cs
- FieldNameLookup.cs
- SspiNegotiationTokenProviderState.cs
- MsmqDiagnostics.cs
- ControlPaint.cs
- RectIndependentAnimationStorage.cs
- Size.cs
- bidPrivateBase.cs
- ShaderEffect.cs
- _KerberosClient.cs
- TableLayoutColumnStyleCollection.cs
- NonVisualControlAttribute.cs
- UnionExpr.cs
- MemberAssignment.cs
- Mappings.cs
- DESCryptoServiceProvider.cs
- GraphicsState.cs
- ImpersonationOption.cs
- ExtenderProvidedPropertyAttribute.cs
- TraceLog.cs
- FontDialog.cs
- UserControlCodeDomTreeGenerator.cs
- DataGridSortCommandEventArgs.cs
- FlowDocumentReader.cs
- ReaderWriterLock.cs
- GroupItemAutomationPeer.cs
- InvocationExpression.cs
- TypeValidationEventArgs.cs
- GridViewColumnHeaderAutomationPeer.cs
- HttpInputStream.cs
- Completion.cs
- TextViewElement.cs
- SqlMethodAttribute.cs
- TTSEngineTypes.cs
- _DisconnectOverlappedAsyncResult.cs
- TextAdaptor.cs
- RetrieveVirtualItemEventArgs.cs
- DbMetaDataFactory.cs
- Exception.cs
- HighlightComponent.cs
- RemoteWebConfigurationHostStream.cs
- BorderSidesEditor.cs
- StartUpEventArgs.cs