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
- TextSimpleMarkerProperties.cs
- GeneralTransform.cs
- FormsAuthenticationCredentials.cs
- HttpListenerException.cs
- ListDesigner.cs
- TableRowCollection.cs
- HostedTransportConfigurationManager.cs
- TextWriterTraceListener.cs
- StackOverflowException.cs
- InternalConfigSettingsFactory.cs
- SerializationIncompleteException.cs
- FrameworkContentElementAutomationPeer.cs
- Misc.cs
- FrameAutomationPeer.cs
- MiniMapControl.xaml.cs
- SingleQueryOperator.cs
- XhtmlBasicImageAdapter.cs
- Converter.cs
- GeneralTransform3DCollection.cs
- SafeRightsManagementQueryHandle.cs
- RegularExpressionValidator.cs
- DependencyProperty.cs
- ListViewItemSelectionChangedEvent.cs
- MbpInfo.cs
- MethodBody.cs
- Ref.cs
- TextRange.cs
- LinearGradientBrush.cs
- StrongNameIdentityPermission.cs
- HttpChannelListener.cs
- VirtualPath.cs
- VariableDesigner.xaml.cs
- UserControlParser.cs
- HtmlTableRowCollection.cs
- GridViewUpdatedEventArgs.cs
- XmlExceptionHelper.cs
- QuotedPrintableStream.cs
- CommonDialog.cs
- FormViewDeletedEventArgs.cs
- TypeViewSchema.cs
- EmptyCollection.cs
- ManagementOptions.cs
- CngProvider.cs
- DateTimePicker.cs
- SendMessageContent.cs
- GraphicsPathIterator.cs
- RequiredFieldValidator.cs
- ClipboardProcessor.cs
- SecurityRuntime.cs
- DynamicDataResources.Designer.cs
- XmlAttributeProperties.cs
- DoubleAnimationUsingKeyFrames.cs
- TaiwanCalendar.cs
- RawContentTypeMapper.cs
- FixedSOMLineRanges.cs
- DataTableClearEvent.cs
- CompensationDesigner.cs
- SafeFileMappingHandle.cs
- GraphicsPathIterator.cs
- ValidationSummary.cs
- AutomationPropertyInfo.cs
- ServerIdentity.cs
- EntityDesignerUtils.cs
- SafeHandles.cs
- ExpressionBuilderCollection.cs
- DataGridViewTopRowAccessibleObject.cs
- Avt.cs
- BypassElement.cs
- BaseParser.cs
- HtmlEmptyTagControlBuilder.cs
- FileReader.cs
- TextTreeUndoUnit.cs
- ItemCheckedEvent.cs
- DataGridViewCellPaintingEventArgs.cs
- WeakEventManager.cs
- SByteStorage.cs
- SoapIncludeAttribute.cs
- LayoutTable.cs
- ConfigurationLocation.cs
- HttpBufferlessInputStream.cs
- ServiceModelPerformanceCounters.cs
- LongCountAggregationOperator.cs
- CompiledRegexRunner.cs
- ListViewInsertionMark.cs
- CompositeScriptReferenceEventArgs.cs
- MetadataPropertyvalue.cs
- ImageDrawing.cs
- SignedInfo.cs
- MenuItemBinding.cs
- Quaternion.cs
- ImagingCache.cs
- DataGridTextBox.cs
- ListParagraph.cs
- AffineTransform3D.cs
- CustomErrorsSectionWrapper.cs
- List.cs
- LogicalTreeHelper.cs
- PostBackOptions.cs
- PageClientProxyGenerator.cs
- CallContext.cs