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
- EventQueueState.cs
- FunctionQuery.cs
- OleDbDataReader.cs
- _UriSyntax.cs
- SqlBulkCopyColumnMapping.cs
- DateRangeEvent.cs
- PathSegment.cs
- storepermission.cs
- DateTimeFormatInfoScanner.cs
- Privilege.cs
- XamlBrushSerializer.cs
- DataServiceExpressionVisitor.cs
- XhtmlMobileTextWriter.cs
- ToolStripItemClickedEventArgs.cs
- WebHttpSecurityElement.cs
- AnnotationAuthorChangedEventArgs.cs
- Vector3DCollectionValueSerializer.cs
- AnchoredBlock.cs
- DataGridToolTip.cs
- ProcessMessagesAsyncResult.cs
- ColorInterpolationModeValidation.cs
- BaseCollection.cs
- SqlMetaData.cs
- DetailsViewPageEventArgs.cs
- ThicknessAnimation.cs
- DataGridViewCellCollection.cs
- SqlDataSourceFilteringEventArgs.cs
- RoutedEventValueSerializer.cs
- SqlBuffer.cs
- TextElementCollectionHelper.cs
- DiscoveryClientBindingElement.cs
- BamlResourceSerializer.cs
- HtmlInputReset.cs
- PasswordBox.cs
- StyleXamlParser.cs
- SiteMapNodeItemEventArgs.cs
- TraceEventCache.cs
- UrlMappingsModule.cs
- CodeMemberField.cs
- EncoderParameter.cs
- MetadataAssemblyHelper.cs
- Array.cs
- BorderGapMaskConverter.cs
- DataGridViewRowCancelEventArgs.cs
- BindingExpressionBase.cs
- __ComObject.cs
- BitmapInitialize.cs
- ProfilePropertyNameValidator.cs
- ValidationHelper.cs
- XmlSignificantWhitespace.cs
- HttpWriter.cs
- FontFamily.cs
- SortedSet.cs
- Exceptions.cs
- DecoderFallback.cs
- Error.cs
- ParseChildrenAsPropertiesAttribute.cs
- SQLResource.cs
- ClientSession.cs
- BehaviorDragDropEventArgs.cs
- Assembly.cs
- XmlElementAttributes.cs
- SystemShuttingDownException.cs
- TableProviderWrapper.cs
- BuildResultCache.cs
- OracleDateTime.cs
- ProvideValueServiceProvider.cs
- FlowDocumentReaderAutomationPeer.cs
- BooleanConverter.cs
- ISessionStateStore.cs
- CreateParams.cs
- ConfigurationException.cs
- BlurBitmapEffect.cs
- _NetworkingPerfCounters.cs
- WebMethodAttribute.cs
- AesManaged.cs
- BitmapEffectInputConnector.cs
- ContextMenu.cs
- FrameworkContentElement.cs
- ShutDownListener.cs
- CompilerScopeManager.cs
- TableDetailsCollection.cs
- XmlDataCollection.cs
- WeakRefEnumerator.cs
- ObservableDictionary.cs
- HttpInputStream.cs
- CompileXomlTask.cs
- DesignerProperties.cs
- LabelEditEvent.cs
- SamlAssertionKeyIdentifierClause.cs
- CryptoHandle.cs
- HttpCookiesSection.cs
- MethodInfo.cs
- XmlCollation.cs
- BinaryMethodMessage.cs
- EventLogInternal.cs
- Code.cs
- TextRunProperties.cs
- BitVector32.cs
- TextEndOfParagraph.cs