Handle Property

IsolatedStorageFileStream.Handle Property

 
Note: This API is now obsolete.

Gets the file handle for the file that the current IsolatedStorageFileStream object encapsulates. Accessing this property is not permitted on an IsolatedStorageFileStream object, and throws an IsolatedStorageException.

Namespace:   System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)

[ObsoleteAttribute("This property has been deprecated.  Please use IsolatedStorageFileStream's SafeFileHandle property instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public override IntPtr Handle {
	[SecurityCriticalAttribute]
	[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, 
		Flags = SecurityPermissionFlag.UnmanagedCode)]
	get;
}

Property Value

Type: System.IntPtr

The file handle for the file that the current IsolatedStorageFileStream object encapsulates.

Exception Condition
IsolatedStorageException

The Handle property always generates this exception.

For more information, see Handle.

The following code example demonstrates the Handle property.

private bool GetPrefsForUser()
{
    try
    {

        // Retrieve an IsolatedStorageFile for the current Domain and Assembly.
        IsolatedStorageFile isoFile =
            IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly |
            IsolatedStorageScope.Domain,
            null,
            null);

        IsolatedStorageFileStream isoStream =
            new IsolatedStorageFileStream("substituteUsername",
            System.IO.FileMode.Open,
            System.IO.FileAccess.Read,
             System.IO.FileShare.Read);

        // The code executes to this point only if a file corresponding to the username exists.
        // Though you can perform operations on the stream, you cannot get a handle to the file.

        try
        {

            SafeFileHandle aFileHandle = isoStream.SafeFileHandle;
            Console.WriteLine("A pointer to a file handle has been obtained. "
                + aFileHandle.ToString() + " "
                + aFileHandle.GetHashCode());
        }

        catch (Exception e)
        {
            // Handle the exception.
            Console.WriteLine("Expected exception");
            Console.WriteLine(e);
        }

        StreamReader reader = new StreamReader(isoStream);
        // Read the data.
        this.NewsUrl = reader.ReadLine();
        this.SportsUrl = reader.ReadLine();
        reader.Close();
        isoFile.Close();
        return false;
    }
    catch (System.IO.FileNotFoundException)
    {
        // Expected exception if a file cannot be found. This indicates that we have a new user.
        return true;
    }
}

SecurityPermission

for the ability to access unmanaged code. Associated enumeration: SecurityPermissionFlag.UnmanagedCode Security action: LinkDemand.

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft