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
- VisualStyleRenderer.cs
- ValidationSummary.cs
- Button.cs
- SettingsProviderCollection.cs
- ScriptingSectionGroup.cs
- FileLoadException.cs
- GrammarBuilderBase.cs
- DbDeleteCommandTree.cs
- TextLine.cs
- PropertyPath.cs
- wgx_exports.cs
- XmlSchemaSet.cs
- Exceptions.cs
- Attributes.cs
- XmlSignatureProperties.cs
- Lock.cs
- XmlSerializerFactory.cs
- XmlSchemaInclude.cs
- ProxyDataContractResolver.cs
- MarkupProperty.cs
- XMLUtil.cs
- ZipFileInfoCollection.cs
- SafeProcessHandle.cs
- PersistStreamTypeWrapper.cs
- FillRuleValidation.cs
- MessageQueueException.cs
- ChangeInterceptorAttribute.cs
- ServiceReference.cs
- CounterSampleCalculator.cs
- DictionarySectionHandler.cs
- BinHexDecoder.cs
- XhtmlBasicValidationSummaryAdapter.cs
- RotationValidation.cs
- InkCanvasInnerCanvas.cs
- RecognizedAudio.cs
- OdbcConnectionHandle.cs
- PageScaling.cs
- BindingMAnagerBase.cs
- UnsafeNativeMethodsCLR.cs
- StylusSystemGestureEventArgs.cs
- DES.cs
- Wildcard.cs
- ActiveXHost.cs
- TypeName.cs
- ActivityInstanceMap.cs
- DataRowComparer.cs
- X509Extension.cs
- SHA256.cs
- OdbcDataAdapter.cs
- CompareValidator.cs
- WindowsContainer.cs
- EncodingInfo.cs
- WebPart.cs
- SecurityAlgorithmSuite.cs
- WebPartDisplayMode.cs
- WindowsGraphics2.cs
- Normalization.cs
- XmlRawWriter.cs
- RoutedEventHandlerInfo.cs
- DbProviderSpecificTypePropertyAttribute.cs
- Validator.cs
- AccessibleObject.cs
- HtmlInputFile.cs
- QueryResponse.cs
- Marshal.cs
- IndentedTextWriter.cs
- ConfigXmlCDataSection.cs
- AdditionalEntityFunctions.cs
- SchemaAttDef.cs
- ToolStripDropDownClosedEventArgs.cs
- ValueOfAction.cs
- TextDecorationCollectionConverter.cs
- Sequence.cs
- SqlDataSource.cs
- DecimalConverter.cs
- PerformanceCounterPermissionEntryCollection.cs
- ContextMenuStrip.cs
- HtmlInputText.cs
- _Events.cs
- Manipulation.cs
- Mutex.cs
- BufferedGraphics.cs
- printdlgexmarshaler.cs
- MaskedTextBox.cs
- DispatchWrapper.cs
- PropertyMap.cs
- MatrixCamera.cs
- ApplicationCommands.cs
- HttpRuntimeSection.cs
- ReadOnlyDataSourceView.cs
- ScriptResourceInfo.cs
- PublishLicense.cs
- FrugalList.cs
- DataFieldConverter.cs
- BaseUriHelper.cs
- ParameterBuilder.cs
- SupportsEventValidationAttribute.cs
- SamlAction.cs
- ConfigurationSettings.cs
- HostProtectionPermission.cs