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
- XmlDataLoader.cs
- XmlSecureResolver.cs
- ManagedFilter.cs
- SQLDecimal.cs
- ImageUrlEditor.cs
- ApplicationServiceManager.cs
- followingquery.cs
- MessageAction.cs
- WindowsGraphicsCacheManager.cs
- PageParserFilter.cs
- DataControlFieldCell.cs
- ExtentJoinTreeNode.cs
- Axis.cs
- As.cs
- TextLineBreak.cs
- SpellerStatusTable.cs
- CheckBoxList.cs
- RestClientProxyHandler.cs
- Trigger.cs
- InternalSafeNativeMethods.cs
- SchemaType.cs
- DataGridViewRowsAddedEventArgs.cs
- FontSource.cs
- TreeViewEvent.cs
- XamlBrushSerializer.cs
- WizardForm.cs
- MissingMethodException.cs
- TextTreeTextBlock.cs
- ToolStripControlHost.cs
- Optimizer.cs
- MenuItemCollection.cs
- DbBuffer.cs
- CodeArgumentReferenceExpression.cs
- SplashScreenNativeMethods.cs
- X509Certificate2.cs
- ShapingWorkspace.cs
- bidPrivateBase.cs
- DataBoundControl.cs
- RemotingException.cs
- ThrowOnMultipleAssignment.cs
- DnsPermission.cs
- ProjectionPlanCompiler.cs
- Statements.cs
- RijndaelCryptoServiceProvider.cs
- SQLBoolean.cs
- ISessionStateStore.cs
- PrincipalPermission.cs
- HtmlCalendarAdapter.cs
- DeviceContexts.cs
- BroadcastEventHelper.cs
- LineInfo.cs
- HyperLinkField.cs
- DbConnectionClosed.cs
- TabControlEvent.cs
- OperationCanceledException.cs
- SqlBuilder.cs
- Quack.cs
- AxImporter.cs
- Pen.cs
- DataObjectEventArgs.cs
- SQLInt64Storage.cs
- ProxyHelper.cs
- Int32Rect.cs
- AttributeAction.cs
- HttpsHostedTransportConfiguration.cs
- NavigationFailedEventArgs.cs
- ArraySegment.cs
- FontInfo.cs
- IconEditor.cs
- WebSysDescriptionAttribute.cs
- MonthCalendarDesigner.cs
- StreamSecurityUpgradeProvider.cs
- SqlConnectionHelper.cs
- TreeNode.cs
- XMLSchema.cs
- OleDbFactory.cs
- IgnoreSection.cs
- Grant.cs
- ContainerParagraph.cs
- TraceHandler.cs
- FontUnit.cs
- ViewValidator.cs
- LabelLiteral.cs
- ValidateNames.cs
- TrackingMemoryStream.cs
- ConfigXmlReader.cs
- Bitmap.cs
- RetrieveVirtualItemEventArgs.cs
- EpmCustomContentDeSerializer.cs
- ClientFormsAuthenticationCredentials.cs
- HttpConfigurationContext.cs
- FontStretchConverter.cs
- SelectionProcessor.cs
- AttachedPropertyMethodSelector.cs
- oledbmetadatacolumnnames.cs
- DecodeHelper.cs
- KeyedCollection.cs
- XmlAtomicValue.cs
- RecordsAffectedEventArgs.cs
- OuterGlowBitmapEffect.cs