Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / FileUtil.cs / 1305376 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlGenericUtil.cs
- TextRange.cs
- SecurityHelper.cs
- Util.cs
- CookieParameter.cs
- GCHandleCookieTable.cs
- DrawListViewItemEventArgs.cs
- InvokeWebServiceDesigner.cs
- XmlCharCheckingReader.cs
- StrongNameUtility.cs
- DataRow.cs
- EncryptedType.cs
- TextTreeTextNode.cs
- DataControlReference.cs
- TableCell.cs
- SoapSchemaExporter.cs
- DataGridCell.cs
- MultilineStringConverter.cs
- UserControlParser.cs
- UDPClient.cs
- DefaultSerializationProviderAttribute.cs
- TypeCollectionPropertyEditor.cs
- ScrollProperties.cs
- PeerInvitationResponse.cs
- SqlCacheDependencyDatabase.cs
- SettingsProperty.cs
- XPathDocument.cs
- LogicalExpr.cs
- ParsedAttributeCollection.cs
- ParsedAttributeCollection.cs
- TextAnchor.cs
- CreateRefExpr.cs
- DateTimeConverter.cs
- ConfigurationElement.cs
- WebBaseEventKeyComparer.cs
- PropertyToken.cs
- Ipv6Element.cs
- WinInet.cs
- XmlAttributeAttribute.cs
- ExpandCollapseProviderWrapper.cs
- HtmlInputText.cs
- OptimizedTemplateContent.cs
- ResolvedKeyFrameEntry.cs
- ServiceEndpointElementCollection.cs
- EventLogEntryCollection.cs
- WeakReference.cs
- PerformanceCounterPermissionEntry.cs
- PipelineModuleStepContainer.cs
- TiffBitmapEncoder.cs
- MetadataArtifactLoaderComposite.cs
- PerfCounters.cs
- Int32Rect.cs
- ListDataHelper.cs
- PriorityQueue.cs
- OleCmdHelper.cs
- TableCell.cs
- AssemblyName.cs
- XmlCustomFormatter.cs
- TableAdapterManagerNameHandler.cs
- DragDrop.cs
- InlineUIContainer.cs
- UserPreferenceChangedEventArgs.cs
- GZipStream.cs
- Columns.cs
- DesignerDataParameter.cs
- StrongBox.cs
- HtmlFormParameterReader.cs
- CategoryGridEntry.cs
- EmptyControlCollection.cs
- UnmanagedHandle.cs
- ISAPIApplicationHost.cs
- ProcessRequestAsyncResult.cs
- LinqMaximalSubtreeNominator.cs
- ListItemParagraph.cs
- WindowsListViewItemCheckBox.cs
- AliasedSlot.cs
- DataContractAttribute.cs
- AccessDataSourceDesigner.cs
- Freezable.cs
- LocalFileSettingsProvider.cs
- WebScriptMetadataMessageEncodingBindingElement.cs
- ByteConverter.cs
- xamlnodes.cs
- Int32Rect.cs
- SourceInterpreter.cs
- EndpointBehaviorElementCollection.cs
- RSAOAEPKeyExchangeFormatter.cs
- Publisher.cs
- StylusLogic.cs
- DateTimeOffsetStorage.cs
- DbUpdateCommandTree.cs
- Delegate.cs
- AutoCompleteStringCollection.cs
- CalendarDataBindingHandler.cs
- FilteredReadOnlyMetadataCollection.cs
- IPAddress.cs
- ToolboxItem.cs
- EntityTransaction.cs
- SpecialNameAttribute.cs
- ViewUtilities.cs