Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- DeferredTextReference.cs
- MemberRelationshipService.cs
- BamlMapTable.cs
- ArgIterator.cs
- PathFigure.cs
- EntityDataSourceValidationException.cs
- ElementFactory.cs
- Geometry3D.cs
- XmlSchemaNotation.cs
- AnnotationDocumentPaginator.cs
- UserControlParser.cs
- ComplusTypeValidator.cs
- DiagnosticTraceSource.cs
- WindowsAltTab.cs
- ComEventsSink.cs
- SmiXetterAccessMap.cs
- PlaceHolder.cs
- HandleValueEditor.cs
- WeakReferenceList.cs
- WinFormsComponentEditor.cs
- ResourcePropertyMemberCodeDomSerializer.cs
- InteropBitmapSource.cs
- SplayTreeNode.cs
- FastPropertyAccessor.cs
- ReceiveActivity.cs
- OfTypeExpression.cs
- OleDbRowUpdatedEvent.cs
- UnSafeCharBuffer.cs
- InvokePattern.cs
- LocatorPart.cs
- TextElementCollectionHelper.cs
- ProjectionNode.cs
- ValidationError.cs
- TypeBuilder.cs
- VSWCFServiceContractGenerator.cs
- ComponentResourceManager.cs
- AssociatedControlConverter.cs
- SQLDecimalStorage.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- DefaultTextStore.cs
- CryptoProvider.cs
- NavigationWindowAutomationPeer.cs
- PasswordBox.cs
- CompositeControl.cs
- MgmtConfigurationRecord.cs
- DictionaryEditChange.cs
- CompiledRegexRunner.cs
- FontCollection.cs
- HitTestDrawingContextWalker.cs
- AssemblyAttributesGoHere.cs
- RijndaelCryptoServiceProvider.cs
- TextHidden.cs
- SettingsSection.cs
- QilInvokeLateBound.cs
- XmlNamedNodeMap.cs
- ErrorsHelper.cs
- HtmlLink.cs
- Frame.cs
- NamespaceEmitter.cs
- TokenBasedSet.cs
- BuildProvider.cs
- SchemaMapping.cs
- DeleteWorkflowOwnerCommand.cs
- CodeLabeledStatement.cs
- ObjectPersistData.cs
- EncoderBestFitFallback.cs
- XmlNotation.cs
- IndicFontClient.cs
- X509Certificate2Collection.cs
- LowerCaseStringConverter.cs
- input.cs
- WebPartZoneBaseDesigner.cs
- ToolStripPanelSelectionBehavior.cs
- MimeTextImporter.cs
- RegisteredArrayDeclaration.cs
- XmlDictionaryString.cs
- ProfileEventArgs.cs
- UserControl.cs
- EncodingNLS.cs
- Manipulation.cs
- XmlMemberMapping.cs
- UIElementAutomationPeer.cs
- pingexception.cs
- PrinterUnitConvert.cs
- ScalarType.cs
- KeyFrames.cs
- ScriptingWebServicesSectionGroup.cs
- WebPartHelpVerb.cs
- LinkConverter.cs
- ErrorLog.cs
- Stack.cs
- _SafeNetHandles.cs
- ImpersonationContext.cs
- FactoryRecord.cs
- CodeMemberEvent.cs
- IApplicationTrustManager.cs
- PlatformCulture.cs
- CollectionBuilder.cs
- RecognizerInfo.cs
- HttpDebugHandler.cs