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
- TagPrefixInfo.cs
- CompareValidator.cs
- OracleFactory.cs
- OutputWindow.cs
- SrgsItemList.cs
- ExtensionWindowHeader.cs
- SystemIcmpV6Statistics.cs
- ServiceContractListItem.cs
- UnsafeNativeMethods.cs
- UnicodeEncoding.cs
- ListBindingHelper.cs
- CachedCompositeFamily.cs
- SQLInt16Storage.cs
- FileSecurity.cs
- ZipIOCentralDirectoryBlock.cs
- RawStylusInputCustomData.cs
- TableLayoutPanelBehavior.cs
- FixedDocument.cs
- MULTI_QI.cs
- RtfControlWordInfo.cs
- ProjectionCamera.cs
- CodeValidator.cs
- LingerOption.cs
- SoapElementAttribute.cs
- ObjectResult.cs
- Visual3DCollection.cs
- HttpListenerContext.cs
- SafeThreadHandle.cs
- TextLineBreak.cs
- ComAdminInterfaces.cs
- storagemappingitemcollection.viewdictionary.cs
- CompositeDataBoundControl.cs
- DataGridViewCellFormattingEventArgs.cs
- IfAction.cs
- CompiledRegexRunnerFactory.cs
- EventLogPermissionEntry.cs
- QueryStringParameter.cs
- HostedNamedPipeTransportManager.cs
- BrushMappingModeValidation.cs
- _AutoWebProxyScriptEngine.cs
- WebServiceClientProxyGenerator.cs
- ChildrenQuery.cs
- Header.cs
- PngBitmapEncoder.cs
- CustomTypeDescriptor.cs
- DataRecord.cs
- CodeTypeParameterCollection.cs
- ButtonFlatAdapter.cs
- SymbolType.cs
- InputLanguageEventArgs.cs
- MaskDescriptor.cs
- XslAst.cs
- DataGridTextBox.cs
- BinaryObjectReader.cs
- securitycriticaldata.cs
- linebase.cs
- XmlTextWriter.cs
- XPathChildIterator.cs
- StylusOverProperty.cs
- SafeHandle.cs
- StubHelpers.cs
- AssemblyBuilder.cs
- EnumerableCollectionView.cs
- InkCanvasFeedbackAdorner.cs
- PictureBox.cs
- LinkUtilities.cs
- TriggerBase.cs
- BuildProviderUtils.cs
- AmbientProperties.cs
- categoryentry.cs
- PassportAuthenticationEventArgs.cs
- CmsInterop.cs
- ImagingCache.cs
- MailWriter.cs
- VarRefManager.cs
- TabControl.cs
- TemplateXamlParser.cs
- Compiler.cs
- EdmRelationshipRoleAttribute.cs
- SchemaInfo.cs
- BitmapSource.cs
- SplineKeyFrames.cs
- DependencyObjectProvider.cs
- RemoteArgument.cs
- XmlUnspecifiedAttribute.cs
- DbExpressionBuilder.cs
- BitmapEffect.cs
- EntityObject.cs
- FtpWebResponse.cs
- EventInfo.cs
- AnonymousIdentificationModule.cs
- MatrixAnimationUsingPath.cs
- Dictionary.cs
- XmlText.cs
- CompareValidator.cs
- OrderPreservingMergeHelper.cs
- DBConnectionString.cs
- AmbientLight.cs
- __Error.cs
- LineInfo.cs