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
- ScopelessEnumAttribute.cs
- LocalClientSecuritySettings.cs
- TimeSpan.cs
- Misc.cs
- RealProxy.cs
- RefExpr.cs
- TypeSource.cs
- TypeExtensionConverter.cs
- OwnerDrawPropertyBag.cs
- ProofTokenCryptoHandle.cs
- Vertex.cs
- QuaternionKeyFrameCollection.cs
- ColumnClickEvent.cs
- SqlNotificationEventArgs.cs
- SafeNativeMethods.cs
- DataRelation.cs
- Grant.cs
- ByteKeyFrameCollection.cs
- DependencyProperty.cs
- TraceHandler.cs
- SemanticAnalyzer.cs
- BamlRecordHelper.cs
- CodeAttributeDeclarationCollection.cs
- MatrixConverter.cs
- ProxyWebPartManager.cs
- Attributes.cs
- Switch.cs
- DataServiceContext.cs
- DecoderExceptionFallback.cs
- EdmRelationshipNavigationPropertyAttribute.cs
- LeftCellWrapper.cs
- EDesignUtil.cs
- ConfigXmlElement.cs
- SendDesigner.xaml.cs
- ListViewItemSelectionChangedEvent.cs
- KeyTime.cs
- ListViewEditEventArgs.cs
- CustomCategoryAttribute.cs
- TypeHelpers.cs
- RichTextBoxAutomationPeer.cs
- MSAAWinEventWrap.cs
- TimerElapsedEvenArgs.cs
- ChangeDirector.cs
- StringUtil.cs
- DocumentViewerBase.cs
- brushes.cs
- RichTextBoxConstants.cs
- CompositeControl.cs
- GZipUtils.cs
- ContainerAction.cs
- NetworkCredential.cs
- HtmlLink.cs
- XmlAttribute.cs
- BaseParaClient.cs
- Stackframe.cs
- FormViewCommandEventArgs.cs
- ProcessHostMapPath.cs
- TaskExtensions.cs
- ScriptRegistrationManager.cs
- SingleBodyParameterMessageFormatter.cs
- XmlSchemaSimpleContentExtension.cs
- BufferedGraphicsContext.cs
- UIElementCollection.cs
- Activity.cs
- ReachSerializableProperties.cs
- AuthStoreRoleProvider.cs
- DecimalConstantAttribute.cs
- IsolationInterop.cs
- AppDomainManager.cs
- XmlElementCollection.cs
- ManagementEventWatcher.cs
- FontDifferentiator.cs
- MarkupCompiler.cs
- TextPointerBase.cs
- ColorContext.cs
- EncoderParameter.cs
- Scheduler.cs
- TemplatePropertyEntry.cs
- UnsafeNativeMethods.cs
- TextEditorLists.cs
- WindowsListViewItemCheckBox.cs
- HideDisabledControlAdapter.cs
- HtmlFormWrapper.cs
- XamlTreeBuilder.cs
- ControlEvent.cs
- TextBoxBase.cs
- _NegotiateClient.cs
- ImageSource.cs
- Error.cs
- SchemaNames.cs
- DataTemplateSelector.cs
- DriveNotFoundException.cs
- SystemSounds.cs
- EdmType.cs
- BitArray.cs
- TrackingParticipant.cs
- DataRelationPropertyDescriptor.cs
- MemberRelationshipService.cs
- RootProjectionNode.cs
- ButtonChrome.cs