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
- StatusBarItem.cs
- _SslState.cs
- RIPEMD160.cs
- TdsParserStaticMethods.cs
- RangeEnumerable.cs
- InputLanguage.cs
- SequentialOutput.cs
- WebBrowserSiteBase.cs
- DataPagerField.cs
- MDIClient.cs
- GlyphingCache.cs
- _NetworkingPerfCounters.cs
- RightsManagementInformation.cs
- processwaithandle.cs
- WeakReadOnlyCollection.cs
- ObjectDataSourceStatusEventArgs.cs
- Logging.cs
- DragCompletedEventArgs.cs
- CodeArgumentReferenceExpression.cs
- DocumentPageHost.cs
- TextRenderer.cs
- Material.cs
- DefaultExpressionVisitor.cs
- GenericWebPart.cs
- PrintDialogDesigner.cs
- DmlSqlGenerator.cs
- ListMarkerLine.cs
- LayeredChannelFactory.cs
- URIFormatException.cs
- DebugView.cs
- ZipIOLocalFileDataDescriptor.cs
- TextEndOfLine.cs
- MarkupObject.cs
- AnnotationMap.cs
- ClientFormsAuthenticationCredentials.cs
- TriggerBase.cs
- PrinterUnitConvert.cs
- Rotation3DAnimationUsingKeyFrames.cs
- RemoteX509Token.cs
- Merger.cs
- QuaternionConverter.cs
- SecurityPolicySection.cs
- InArgument.cs
- XPathPatternBuilder.cs
- SqlReorderer.cs
- StringReader.cs
- SafeNativeMethodsOther.cs
- odbcmetadatacolumnnames.cs
- System.Data.OracleClient_BID.cs
- EndpointNameMessageFilter.cs
- LayoutTable.cs
- ComUdtElement.cs
- ViewBase.cs
- PointConverter.cs
- InitializationEventAttribute.cs
- LogReserveAndAppendState.cs
- AssemblyResourceLoader.cs
- ToolTip.cs
- AnonymousIdentificationModule.cs
- CapabilitiesSection.cs
- LocalBuilder.cs
- FileDialogCustomPlace.cs
- PageClientProxyGenerator.cs
- Set.cs
- UIServiceHelper.cs
- StateInitialization.cs
- BindingGroup.cs
- QilDataSource.cs
- CursorInteropHelper.cs
- Timer.cs
- ValidationVisibilityAttribute.cs
- SortDescription.cs
- AnnotationComponentManager.cs
- CursorConverter.cs
- HtmlElementEventArgs.cs
- SchemaInfo.cs
- SQLMembershipProvider.cs
- TypedElement.cs
- GPPOINT.cs
- BindingWorker.cs
- AsynchronousChannelMergeEnumerator.cs
- ExpressionBinding.cs
- ConfigXmlCDataSection.cs
- NullableLongAverageAggregationOperator.cs
- MarshalDirectiveException.cs
- CachedPathData.cs
- HtmlCommandAdapter.cs
- WriteTimeStream.cs
- ObjectKeyFrameCollection.cs
- XmlProcessingInstruction.cs
- SystemInfo.cs
- AggregatePushdown.cs
- ObjectRef.cs
- Assembly.cs
- PostBackTrigger.cs
- OperationCanceledException.cs
- Condition.cs
- MultilineStringConverter.cs
- ColorConvertedBitmap.cs
- NameValueSectionHandler.cs