IsolatedStorageFileStream Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Espone un file all'interno dello spazio di memorizzazione isolato.
public ref class IsolatedStorageFileStream : System::IO::Stream
public ref class IsolatedStorageFileStream : System::IO::FileStream
public class IsolatedStorageFileStream : System.IO.Stream
public class IsolatedStorageFileStream : System.IO.FileStream
[System.Runtime.InteropServices.ComVisible(true)]
public class IsolatedStorageFileStream : System.IO.FileStream
type IsolatedStorageFileStream = class
inherit Stream
type IsolatedStorageFileStream = class
inherit FileStream
[<System.Runtime.InteropServices.ComVisible(true)>]
type IsolatedStorageFileStream = class
inherit FileStream
Public Class IsolatedStorageFileStream
Inherits Stream
Public Class IsolatedStorageFileStream
Inherits FileStream
- Ereditarietà
- Ereditarietà
- Attributi
Esempio
L'applicazione console seguente illustra come usare IsolatedStorageFile e IsolatedStorageFileStream scrivere dati in un file di archiviazione isolata. All'utente viene richiesto di accedere. Se l'utente è un nuovo utente, un URL notizie e un URL sportivo vengono registrati come preferenze personali in Archiviazione isolata. Se l'utente è un utente che restituisce, vengono visualizzate le preferenze correnti dell'utente. Gli esempi di codice usati in questo spazio dei nomi vengono presentati nel contesto di questa applicazione di esempio. È possibile usare l'utilità Storeadm.exe (Strumento di archiviazione isolata) per elencare e rimuovere i file di archiviazione isolata creati con questa applicazione console.
// This sample demonstrates methods of classes found in the System.IO IsolatedStorage namespace.
using namespace System;
using namespace System::IO;
using namespace System::IO::IsolatedStorage;
using namespace System::Security::Policy;
using namespace System::Security::Permissions;
public ref class LoginPrefs
{
private:
String^ userName;
String^ newsUrl;
String^ sportsUrl;
bool newPrefs;
public:
[SecurityPermissionAttribute(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
bool GetPrefsForUser()
{
try
{
// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), (Type^)nullptr, nullptr );
IsolatedStorageFileStream^ isoStream = gcnew IsolatedStorageFileStream( this->userName,FileMode::Open,FileAccess::ReadWrite,isoFile );
// farThe 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
{
IntPtr aFileHandle = isoStream->Handle;
Console::WriteLine( "A pointer to a file handle has been obtained. {0} {1}", aFileHandle, aFileHandle.GetHashCode() );
}
catch ( Exception^ e )
{
// Handle the exception.
Console::WriteLine( "Expected exception" );
Console::WriteLine( e->ToString() );
}
StreamReader^ reader = gcnew StreamReader( isoStream );
// Read the data.
this->NewsUrl = reader->ReadLine();
this->SportsUrl = reader->ReadLine();
reader->Close();
isoFile->Close();
isoStream->Close();
return false;
}
catch ( Exception^ e )
{
// Expected exception if a file cannot be found. This indicates that we have a new user.
String^ errorMessage = e->ToString();
return true;
}
}
bool GetIsoStoreInfo()
{
// Get a User store with type evidence for the current Domain and the Assembly.
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid, System::Security::Policy::Url::typeid );
array<String^>^dirNames = isoFile->GetDirectoryNames( "*" );
array<String^>^fileNames = isoFile->GetFileNames( "*" );
// List directories currently in this Isolated Storage.
if ( dirNames->Length > 0 )
{
for ( int i = 0; i < dirNames->Length; ++i )
{
Console::WriteLine( "Directory Name: {0}", dirNames[ i ] );
}
}
// List the files currently in this Isolated Storage.
// The list represents all users who have personal preferences stored for this application.
if ( fileNames->Length > 0 )
{
for ( int i = 0; i < fileNames->Length; ++i )
{
Console::WriteLine( "File Name: {0}", fileNames[ i ] );
}
}
isoFile->Close();
return true;
}
double SetPrefsForUser()
{
try
{
IsolatedStorageFile^ isoFile;
isoFile = IsolatedStorageFile::GetUserStoreForDomain();
// Open or create a writable file.
IsolatedStorageFileStream^ isoStream = gcnew IsolatedStorageFileStream( this->userName,FileMode::OpenOrCreate,FileAccess::Write,isoFile );
StreamWriter^ writer = gcnew StreamWriter( isoStream );
writer->WriteLine( this->NewsUrl );
writer->WriteLine( this->SportsUrl );
// Calculate the amount of space used to record the user's preferences.
double d = isoFile->CurrentSize / isoFile->MaximumSize;
Console::WriteLine( "CurrentSize = {0}", isoFile->CurrentSize.ToString() );
Console::WriteLine( "MaximumSize = {0}", isoFile->MaximumSize.ToString() );
writer->Close();
isoFile->Close();
isoStream->Close();
return d;
}
catch ( Exception^ e )
{
// Add code here to handle the exception.
Console::WriteLine( e->ToString() );
return 0.0;
}
}
void DeleteFiles()
{
try
{
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid, System::Security::Policy::Url::typeid );
array<String^>^dirNames = isoFile->GetDirectoryNames( "*" );
array<String^>^fileNames = isoFile->GetFileNames( "*" );
// List the files currently in this Isolated Storage.
// The list represents all users who have personal
// preferences stored for this application.
if ( fileNames->Length > 0 )
{
for ( int i = 0; i < fileNames->Length; ++i )
{
//Delete the files.
isoFile->DeleteFile( fileNames[ i ] );
}
fileNames = isoFile->GetFileNames( "*" );
}
isoFile->Close();
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
}
// This method deletes directories in the specified Isolated Storage, after first
// deleting the files they contain. In this example, the Archive directory is deleted.
// There should be no other directories in this Isolated Storage.
void DeleteDirectories()
{
try
{
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid, System::Security::Policy::Url::typeid );
array<String^>^dirNames = isoFile->GetDirectoryNames( "*" );
array<String^>^fileNames = isoFile->GetFileNames( "Archive\\*" );
// Delete the current files within the Archive directory.
if ( fileNames->Length > 0 )
{
for ( int i = 0; i < fileNames->Length; ++i )
{
//delete files
isoFile->DeleteFile( String::Concat("Archive\\", fileNames[ i ]) );
}
fileNames = isoFile->GetFileNames( "Archive\\*" );
}
if ( dirNames->Length > 0 )
{
for ( int i = 0; i < dirNames->Length; ++i )
{
// Delete the Archive directory.
isoFile->DeleteDirectory( dirNames[ i ] );
}
}
dirNames = isoFile->GetDirectoryNames( "*" );
isoFile->Remove();
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
}
}
double SetNewPrefsForUser()
{
try
{
Byte inputChar;
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid, System::Security::Policy::Url::typeid );
// If this is not a new user, archive the old preferences and
// overwrite them using the new preferences.
if ( !this->NewPrefs )
{
if ( isoFile->GetDirectoryNames( "Archive" )->Length == 0 )
isoFile->CreateDirectory( "Archive" );
else
{
// This is the stream to which data will be written.
IsolatedStorageFileStream^ source = gcnew IsolatedStorageFileStream( this->userName,FileMode::OpenOrCreate,isoFile );
// This is the stream from which data will be read.
Console::WriteLine( "Is the source file readable? {0}", (source->CanRead ? (String^)"true" : "false") );
Console::WriteLine( "Creating new IsolatedStorageFileStream for Archive." );
// Open or create a writable file.
IsolatedStorageFileStream^ target = gcnew IsolatedStorageFileStream( String::Concat("Archive\\",this->userName),FileMode::OpenOrCreate,FileAccess::Write,FileShare::Write,isoFile );
Console::WriteLine( "Is the target file writable? {0}", (target->CanWrite ? (String^)"true" : "false") );
// Stream the old file to a new file in the Archive directory.
if ( source->IsAsync && target->IsAsync )
{
// IsolatedStorageFileStreams cannot be asynchronous. However, you
// can use the asynchronous BeginRead and BeginWrite functions
// with some possible performance penalty.
Console::WriteLine( "IsolatedStorageFileStreams cannot be asynchronous." );
}
else
{
Console::WriteLine( "Writing data to the new file." );
while ( source->Position < source->Length )
{
inputChar = (Byte)source->ReadByte();
target->WriteByte( (Byte)source->ReadByte() );
}
// Determine the size of the IsolatedStorageFileStream
// by checking its Length property.
Console::WriteLine( "Total Bytes Read: {0}", source->Length.ToString() );
}
// After you have read and written to the streams, close them.
target->Close();
source->Close();
}
}
// Open or create a writable file, no larger than 10k
IsolatedStorageFileStream^ isoStream = gcnew IsolatedStorageFileStream( this->userName,FileMode::OpenOrCreate,FileAccess::Write,FileShare::Write,10240,isoFile );
isoStream->Position = 0; // Position to overwrite the old data.
StreamWriter^ writer = gcnew StreamWriter( isoStream );
// Update the data based on the new inputs.
writer->WriteLine( this->NewsUrl );
writer->WriteLine( this->SportsUrl );
// Calculate the amount of space used to record this user's preferences.
double d = isoFile->CurrentSize / isoFile->MaximumSize;
Console::WriteLine( "CurrentSize = {0}", isoFile->CurrentSize.ToString() );
Console::WriteLine( "MaximumSize = {0}", isoFile->MaximumSize.ToString() );
// StreamWriter.Close implicitly closes isoStream.
writer->Close();
isoFile->Close();
return d;
}
catch ( Exception^ e )
{
Console::WriteLine( e->ToString() );
return 0.0;
}
}
LoginPrefs( String^ aUserName )
{
userName = aUserName;
newPrefs = GetPrefsForUser();
}
property String^ NewsUrl
{
String^ get()
{
return newsUrl;
}
void set( String^ value )
{
newsUrl = value;
}
}
property String^ SportsUrl
{
String^ get()
{
return sportsUrl;
}
void set( String^ value )
{
sportsUrl = value;
}
}
property bool NewPrefs
{
bool get()
{
return newPrefs;
}
}
};
void GatherInfoFromUser( LoginPrefs^ lp )
{
Console::WriteLine( "Please enter the URL of your news site." );
lp->NewsUrl = Console::ReadLine();
Console::WriteLine( "Please enter the URL of your sports site." );
lp->SportsUrl = Console::ReadLine();
}
int main()
{
// Prompt the user for their username.
Console::WriteLine( "Enter your login ID:" );
// Does no error checking.
LoginPrefs^ lp = gcnew LoginPrefs( Console::ReadLine() );
if ( lp->NewPrefs )
{
Console::WriteLine( "Please set preferences for a new user." );
GatherInfoFromUser( lp );
// Write the new preferences to storage.
double percentUsed = lp->SetPrefsForUser();
Console::WriteLine( "Your preferences have been written. Current space used is {0}%", percentUsed );
}
else
{
Console::WriteLine( "Welcome back." );
Console::WriteLine( "Your preferences have expired, please reset them." );
GatherInfoFromUser( lp );
lp->SetNewPrefsForUser();
Console::WriteLine( "Your news site has been set to {0}\n and your sports site has been set to {1}.", lp->NewsUrl, lp->SportsUrl );
}
lp->GetIsoStoreInfo();
Console::WriteLine( "Enter 'd' to delete the IsolatedStorage files and exit, or press any other key to exit without deleting files." );
String^ consoleInput = Console::ReadLine();
if ( consoleInput->Equals( "d" ) )
{
lp->DeleteFiles();
lp->DeleteDirectories();
}
}
// This sample demonstrates methods of classes found in the System.IO IsolatedStorage namespace.
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Security.Policy;
using Microsoft.Win32.SafeHandles;
[assembly: CLSCompliantAttribute(true)]
class ConsoleApp
{
[STAThread]
static void Main(string[] args)
{
// Prompt the user for their username.
Console.WriteLine("Login:");
// Does no error checking.
LoginPrefs lp = new LoginPrefs(Console.ReadLine());
if (lp.NewPrefs)
{
Console.WriteLine("Please set preferences for a new user.");
GatherInfoFromUser(lp);
// Write the new preferences to storage.
double percentUsed = lp.SetPrefsForUser();
Console.WriteLine("Your preferences have been written. Current space used is " + percentUsed.ToString() + " %");
}
else
{
Console.WriteLine("Welcome back.");
Console.WriteLine("Your preferences have expired, please reset them.");
GatherInfoFromUser(lp);
lp.SetNewPrefsForUser();
Console.WriteLine("Your news site has been set to {0}\n and your sports site has been set to {1}.", lp.NewsUrl, lp.SportsUrl);
}
lp.GetIsoStoreInfo();
Console.WriteLine("Enter 'd' to delete the IsolatedStorage files and exit, or press any other key to exit without deleting files.");
string consoleInput = Console.ReadLine();
if (consoleInput.ToLower() == "d")
{
lp.DeleteFiles();
lp.DeleteDirectories();
}
}
static void GatherInfoFromUser(LoginPrefs lp)
{
Console.WriteLine("Please enter the URL of your news site.");
lp.NewsUrl = Console.ReadLine();
Console.WriteLine("Please enter the URL of your sports site.");
lp.SportsUrl = Console.ReadLine();
}
}
public class LoginPrefs
{
public LoginPrefs(string myUserName)
{
userName = myUserName;
myNewPrefs = GetPrefsForUser();
}
string userName;
string myNewsUrl;
public string NewsUrl
{
get { return myNewsUrl; }
set { myNewsUrl = value; }
}
string mySportsUrl;
public string SportsUrl
{
get { return mySportsUrl; }
set { mySportsUrl = value; }
}
bool myNewPrefs;
public bool NewPrefs
{
get { return myNewPrefs; }
}
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;
}
}
public bool GetIsoStoreInfo()
{
// Get a User store with type evidence for the current Domain and the Assembly.
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("*");
// List directories currently in this Isolated Storage.
if (dirNames.Length > 0)
{
for (int i = 0; i < dirNames.Length; ++i)
{
Console.WriteLine("Directory Name: " + dirNames[i]);
}
}
// List the files currently in this Isolated Storage.
// The list represents all users who have personal preferences stored for this application.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
Console.WriteLine("File Name: " + fileNames[i]);
}
}
isoFile.Close();
return true;
}
public double SetPrefsForUser()
{
try
{
IsolatedStorageFile isoFile;
isoFile = IsolatedStorageFile.GetUserStoreForDomain();
// Open or create a writable file.
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
isoFile);
StreamWriter writer = new StreamWriter(isoStream);
writer.WriteLine(this.NewsUrl);
writer.WriteLine(this.SportsUrl);
// Calculate the amount of space used to record the user's preferences.
double d = isoFile.CurrentSize / isoFile.MaximumSize;
Console.WriteLine("CurrentSize = " + isoFile.CurrentSize.ToString());
Console.WriteLine("MaximumSize = " + isoFile.MaximumSize.ToString());
// StreamWriter.Close implicitly closes isoStream.
writer.Close();
isoFile.Dispose();
isoFile.Close();
return d;
}
catch (IsolatedStorageException ex)
{
// Add code here to handle the exception.
Console.WriteLine(ex);
return 0.0;
}
}
public void DeleteFiles()
{
try
{
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("*");
// List the files currently in this Isolated Storage.
// The list represents all users who have personal
// preferences stored for this application.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
// Delete the files.
isoFile.DeleteFile(fileNames[i]);
}
// Confirm that no files remain.
fileNames = isoFile.GetFileNames("*");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
// This method deletes directories in the specified Isolated Storage, after first
// deleting the files they contain. In this example, the Archive directory is deleted.
// There should be no other directories in this Isolated Storage.
public void DeleteDirectories()
{
try
{
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
String[] dirNames = isoFile.GetDirectoryNames("*");
String[] fileNames = isoFile.GetFileNames("Archive\\*");
// Delete all the files currently in the Archive directory.
if (fileNames.Length > 0)
{
for (int i = 0; i < fileNames.Length; ++i)
{
// Delete the files.
isoFile.DeleteFile("Archive\\" + fileNames[i]);
}
// Confirm that no files remain.
fileNames = isoFile.GetFileNames("Archive\\*");
}
if (dirNames.Length > 0)
{
for (int i = 0; i < dirNames.Length; ++i)
{
// Delete the Archive directory.
}
}
dirNames = isoFile.GetDirectoryNames("*");
isoFile.Remove();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public double SetNewPrefsForUser()
{
try
{
byte inputChar;
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
// If this is not a new user, archive the old preferences and
// overwrite them using the new preferences.
if (!this.myNewPrefs)
{
if (isoFile.GetDirectoryNames("Archive").Length == 0)
{
isoFile.CreateDirectory("Archive");
}
else
{
IsolatedStorageFileStream source =
new IsolatedStorageFileStream(this.userName, FileMode.OpenOrCreate,
isoFile);
// This is the stream from which data will be read.
Console.WriteLine("Is the source file readable? " + (source.CanRead ? "true" : "false"));
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.");
// Open or create a writable file.
IsolatedStorageFileStream target =
new IsolatedStorageFileStream("Archive\\ " + this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
isoFile);
Console.WriteLine("Is the target file writable? " + (target.CanWrite ? "true" : "false"));
// Stream the old file to a new file in the Archive directory.
if (source.IsAsync && target.IsAsync)
{
// IsolatedStorageFileStreams cannot be asynchronous. However, you
// can use the asynchronous BeginRead and BeginWrite functions
// with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.");
}
else
{
Console.WriteLine("Writing data to the new file.");
while (source.Position < source.Length)
{
inputChar = (byte)source.ReadByte();
target.WriteByte(inputChar);
}
// Determine the size of the IsolatedStorageFileStream
// by checking its Length property.
Console.WriteLine("Total Bytes Read: " + source.Length);
}
// After you have read and written to the streams, close them.
target.Close();
source.Close();
}
}
// Open or create a writable file with a maximum size of 10K.
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
10240,
isoFile);
isoStream.Position = 0; // Position to overwrite the old data.
StreamWriter writer = new StreamWriter(isoStream);
// Update the data based on the new inputs.
writer.WriteLine(this.NewsUrl);
writer.WriteLine(this.SportsUrl);
// Calculate the amount of space used to record this user's preferences.
double d = isoFile.CurrentSize / isoFile.MaximumSize;
Console.WriteLine("CurrentSize = " + isoFile.CurrentSize.ToString());
Console.WriteLine("MaximumSize = " + isoFile.MaximumSize.ToString());
// StreamWriter.Close implicitly closes isoStream.
writer.Close();
isoFile.Close();
return d;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return 0.0;
}
}
}
'This sample demonstrates methods of classes found in the System.IO IsolatedStorage namespace.
Imports System.IO
Imports System.IO.IsolatedStorage
Imports System.Security.Policy
Imports Microsoft.Win32.SafeHandles
Imports System.Security.Permissions
Namespace ISOCS
_
Class ConsoleApp
<STAThread()> _
Overloads Shared Sub Main(ByVal args() As String)
' Prompt the user for their username.
Console.WriteLine("Enter your login ID:")
' Does no error checking.
Dim lp As New LoginPrefs(Console.ReadLine())
If lp.NewPrefs Then
Console.WriteLine("Please set preferences for a new user.")
GatherInfoFromUser(lp)
' Write the new preferences to storage.
Dim percentUsed As Double = lp.SetPrefsForUser()
Console.WriteLine(("Your preferences have been written. Current space used is " & percentUsed.ToString() & " %"))
Else
Console.WriteLine("Welcome back.")
Console.WriteLine("Your preferences have expired, please reset them.")
GatherInfoFromUser(lp)
lp.SetNewPrefsForUser()
Console.WriteLine("Your news site has been set to {0}" & ControlChars.Cr & " and your sports site has been set to {1}.", lp.NewsUrl, lp.SportsUrl)
End If
lp.GetIsoStoreInfo()
Console.WriteLine("Enter 'd' to delete the IsolatedStorage files and exit, or press any other key to exit without deleting files.")
Dim consoleInput As String = Console.ReadLine()
If consoleInput.ToLower() = "d" Then
lp.DeleteFiles()
lp.DeleteDirectories()
End If
End Sub
Shared Sub GatherInfoFromUser(ByVal lp As LoginPrefs)
Console.WriteLine("Please enter the URL of your news site.")
lp.NewsUrl = Console.ReadLine()
Console.WriteLine("Please enter the URL of your sports site.")
lp.SportsUrl = Console.ReadLine()
End Sub
End Class
_
<SecurityPermissionAttribute(SecurityAction.Demand, Flags:=SecurityPermissionFlag.UnmanagedCode)> _
Public Class LoginPrefs
Public Sub New(ByVal myUserName As String)
userName = myUserName
myNewPrefs = GetPrefsForUser()
End Sub
Private userName As String
Private myNewsUrl As String
Public Property NewsUrl() As String
Get
Return myNewsUrl
End Get
Set(ByVal Value As String)
myNewsUrl = Value
End Set
End Property
Private mySportsUrl As String
Public Property SportsUrl() As String
Get
Return mySportsUrl
End Get
Set(ByVal Value As String)
mySportsUrl = Value
End Set
End Property
Private myNewPrefs As Boolean
Public ReadOnly Property NewPrefs() As Boolean
Get
Return myNewPrefs
End Get
End Property
Private Function GetPrefsForUser() As Boolean
Try
' Retrieve an IsolatedStorageFile for the current Domain and Assembly.
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
Or IsolatedStorageScope.Assembly _
Or IsolatedStorageScope.Domain, Nothing, Nothing)
Dim isoStream As New IsolatedStorageFileStream("substituteUsername", System.IO.FileMode.Open, _
System.IO.FileAccess.Read, System.IO.FileShare.Read)
' farThe 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
Dim aFileHandle As SafeFileHandle = isoStream.SafeFileHandle
Console.WriteLine(("A pointer to a file handle has been obtained. " & aFileHandle.ToString() & " " & aFileHandle.GetHashCode()))
Catch ex As Exception
' Handle the exception.
Console.WriteLine("Expected exception")
Console.WriteLine(ex.ToString())
End Try
Dim reader As New StreamReader(isoStream)
' Read the data.
Me.NewsUrl = reader.ReadLine()
Me.SportsUrl = reader.ReadLine()
reader.Close()
isoFile.Close()
Return False
Catch ex As System.IO.FileNotFoundException
' Expected exception if a file cannot be found. This indicates that we have a new user.
Return True
End Try
End Function 'GetPrefsForUser
Public Function GetIsoStoreInfo() As Boolean
Try
'Get a User store with type evidence for the current Domain and the Assembly.
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("*")
Dim name As String
' List directories currently in this Isolated Storage.
If dirNames.Length > 0 Then
For Each name In dirNames
Console.WriteLine("Directory Name: " & name)
Next name
End If
' List the files currently in this Isolated Storage.
' The list represents all users who have personal preferences stored for this application.
If fileNames.Length > 0 Then
For Each name In fileNames
Console.WriteLine("File Name: " & name)
Next name
End If
isoFile.Close()
Return True
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Function 'GetIsoStoreInfo
Public Function SetPrefsForUser() As Double
Try
Dim isoFile As IsolatedStorageFile
isoFile = IsolatedStorageFile.GetUserStoreForDomain()
' Open or create a writable file.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
FileAccess.Write, isoFile)
Dim writer As New StreamWriter(isoStream)
writer.WriteLine(Me.NewsUrl)
writer.WriteLine(Me.SportsUrl)
' Calculate the amount of space used to record the user's preferences.
Dim d As Double = Convert.ToDouble(isoFile.CurrentSize) / Convert.ToDouble(isoFile.MaximumSize)
Console.WriteLine(("CurrentSize = " & isoFile.CurrentSize.ToString()))
Console.WriteLine(("MaximumSize = " & isoFile.MaximumSize.ToString()))
' StreamWriter.Close implicitly closes isoStream.
writer.Close()
isoFile.Dispose()
isoFile.Close()
Return d
Catch ex As Exception
' Add code here to handle the exception.
Console.WriteLine(ex)
Return 0.0
End Try
End Function 'SetPrefsForUser
Public Sub DeleteFiles()
Try
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim name As String
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("*")
' List the files currently in this Isolated Storage.
' The list represents all users who have personal
' preferences stored for this application.
If fileNames.Length > 0 Then
For Each name In fileNames
' Delete the files.
isoFile.DeleteFile(name)
Next name
'Confirm no files are left.
fileNames = isoFile.GetFileNames("*")
End If
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub
' This method deletes directories in the specified Isolated Storage, after first
' deleting the files they contain. In this example, the Archive directory is deleted.
' There should be no other directories in this Isolated Storage.
Public Sub DeleteDirectories()
Try
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
Dim name As String
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("Archive\*")
' Delete all the files currently in the Archive directory.
If fileNames.Length > 0 Then
For Each name In fileNames
isoFile.DeleteFile(("Archive\" & name))
Next name
'Confirm no files are left.
fileNames = isoFile.GetFileNames("Archive\*")
End If
If dirNames.Length > 0 Then
For Each name In dirNames
' Delete the Archive directory.
isoFile.DeleteDirectory(name)
Next name
End If
dirNames = isoFile.GetDirectoryNames("*")
isoFile.Remove()
Catch ex As Exception
Console.WriteLine(ex.ToString())
End Try
End Sub
Public Function SetNewPrefsForUser() As Double
Try
Dim inputChar As Byte
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
' If this is not a new user, archive the old preferences and
' overwrite them using the new preferences.
If Not Me.myNewPrefs Then
If isoFile.GetDirectoryNames("Archive").Length = 0 Then
isoFile.CreateDirectory("Archive")
Else
Dim source As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, isoFile)
Dim canWrite, canRead As Boolean
' This is the stream from which data will be read.
If source.CanRead Then canRead = True Else canRead = False
Console.WriteLine("Is the source file readable? " & canRead)
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.")
' Open or create a writable file.
Dim target As New IsolatedStorageFileStream("Archive\ " & Me.userName, _
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
' This is the stream to which data will be written.
If target.CanWrite Then canWrite = True Else canWrite = False
Console.WriteLine("Is the target file writable? " & canWrite)
target.SetLength(0) 'rewind the target file
' Stream the old file to a new file in the Archive directory.
If source.IsAsync And target.IsAsync Then
' IsolatedStorageFileStreams cannot be asynchronous. However, you
' can use the asynchronous BeginRead and BeginWrite functions
' with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.")
Else
Console.WriteLine("Writing data to the new file.")
While source.Position < source.Length
inputChar = CByte(source.ReadByte())
target.WriteByte(inputChar)
End While
' Determine the size of the IsolatedStorageFileStream
' by checking its Length property.
Console.WriteLine(("Total Bytes Read: " & source.Length))
End If
' After you have read and written to the streams, close them.
target.Close()
source.Close()
End If
End If
' Open or create a writable file with a maximum size of 10K.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
FileAccess.Write, FileShare.Write, 10240, isoFile)
isoStream.SetLength(0) 'Position to overwrite the old data.
Dim writer As New StreamWriter(isoStream)
' Update the data based on the new inputs.
writer.WriteLine(Me.NewsUrl)
writer.WriteLine(Me.SportsUrl)
' Calculate the amount of space used to record this user's preferences.
Dim d As Double = Convert.ToDouble(isoFile.CurrentSize) / Convert.ToDouble(isoFile.MaximumSize)
Console.WriteLine(("CurrentSize = " & isoFile.CurrentSize.ToString()))
Console.WriteLine(("MaximumSize = " & isoFile.MaximumSize.ToString()))
' StreamWriter.Close implicitly closes isoStream.
writer.Close()
isoFile.Close()
Return d
Catch ex As Exception
Console.WriteLine(ex.ToString())
Return 0.0
End Try
End Function 'SetNewPrefsForUser
End Class
End Namespace 'ISOCS
Commenti
Usare questa classe per leggere, scrivere e creare file in un archivio isolato.
Poiché questa classe estende FileStream, è possibile usare un'istanza di nella maggior parte delle IsolatedStorageFileStream situazioni in cui un FileStream oggetto potrebbe essere usato in caso contrario, ad esempio per costruire un StreamReader oggetto o StreamWriter.
Il tipo implementa l'interfaccia IDisposable. Dopo aver utilizzato il tipo, è necessario eliminarlo direttamente o indirettamente. Per eliminare direttamente il tipo, chiamare il metodo Dispose in un blocco try
/catch
. Per eliminarlo indirettamente, utilizzare un costrutto di linguaggio come ad esempio using
in C# o Using
in Visual Basic. Per altre informazioni, vedere la sezione "Uso di un oggetto che implementa IDisposable" nell'argomento relativo all'interfaccia IDisposable.
Importante
L'archiviazione isolata non è disponibile per le app di Windows 8.x Store. Al contrario, usare le classi di dati dell'applicazione negli spazi dei nomi Windows.Storage
inclusi nell'API di Windows Runtime per archiviare dati e file locali. Per altre informazioni, vedere Dati dell'applicazione nel Centro per sviluppatori Windows.
Costruttori
IsolatedStorageFileStream(String, FileMode) |
Inizializza una nuova istanza di un oggetto IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, Int32, IsolatedStorageFile) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess, FileShare, IsolatedStorageFile) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, FileAccess, IsolatedStorageFile) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
IsolatedStorageFileStream(String, FileMode, IsolatedStorageFile) |
Inizializza una nuova istanza della classe IsolatedStorageFileStream dando accesso al file designato da |
Proprietà
CanRead |
Ottiene un valore booleano che indica se è possibile leggere il file. |
CanSeek |
Ottiene un valore booleano che indica se le operazioni di ricerca sono supportate. |
CanTimeout |
Ottiene un valore che determina se il flusso corrente prevede il timeout. (Ereditato da Stream) |
CanWrite |
Ottiene un valore booleano che indica se è possibile scrivere nel file. |
Handle |
Obsoleti.
Obsoleti.
Obsoleti.
Ottiene l'handle di file relativo al file incapsulato dall'oggetto IsolatedStorageFileStream corrente. Poiché l'accesso a questa proprietà non è consentito su un oggetto IsolatedStorageFileStream, viene generata un'eccezione IsolatedStorageException. |
IsAsync |
Ottiene un valore booleano che indica se l'oggetto IsolatedStorageFileStream è stato aperto in modo sincrono o asincrono. |
Length |
Ottiene la lunghezza dell'oggetto IsolatedStorageFileStream. |
Name |
Ottiene il percorso assoluto del file aperto in |
Position |
Ottiene o imposta la posizione corrente dell'oggetto IsolatedStorageFileStream corrente. |
ReadTimeout |
Ottiene o imposta un valore, in millisecondi, che determina per quanto tempo il flusso tenterà la lettura prima del timeout. (Ereditato da Stream) |
SafeFileHandle |
Ottiene un oggetto SafeFileHandle che rappresenta l'handle di file del sistema operativo per il file incapsulato dall'oggetto IsolatedStorageFileStream corrente. |
SafeFileHandle |
Ottiene un oggetto SafeFileHandle che rappresenta l'handle di file del sistema operativo per il file incapsulato dall'oggetto FileStream corrente. (Ereditato da FileStream) |
WriteTimeout |
Ottiene o imposta un valore, in millisecondi, che determina per quanto tempo il flusso tenterà la scrittura prima del timeout. (Ereditato da Stream) |
Metodi
BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) |
Inizia una lettura asincrona. |
BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) |
Inizia un'operazione di lettura asincrona. Si consiglia di usare ReadAsync(Byte[], Int32, Int32). (Ereditato da Stream) |
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) |
Inizia una scrittura asincrona. |
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) |
Inizia un'operazione di scrittura asincrona. Si consiglia di usare WriteAsync(Byte[], Int32, Int32). (Ereditato da Stream) |
Close() |
Rilascia le risorse associate all'oggetto IsolatedStorageFileStream. |
Close() |
Chiude il flusso corrente e libera le risorse, come socket e handle di file, ad esso associate. Anziché chiamare questo metodo, assicurarsi che il flusso sia eliminato correttamente. (Ereditato da Stream) |
Close() |
Chiude il flusso corrente e libera le risorse, come socket e handle di file, ad esso associate. (Ereditato da FileStream) |
CopyTo(Stream) |
Legge i byte dal flusso corrente e li scrive in un altro flusso. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyTo(Stream, Int32) |
Legge tutti i byte dal flusso corrente e li scrive in un altro flusso, usando una dimensione di buffer specificata. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyTo(Stream, Int32) |
Espone un file all'interno dello spazio di memorizzazione isolato. (Ereditato da FileStream) |
CopyToAsync(Stream) |
Legge in modo asincrono i byte dal flusso corrente e li scrive in un altro flusso. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyToAsync(Stream, CancellationToken) |
Legge in modo asincrono i byte dal flusso corrente e li scrive in un altro flusso, usando un token di annullamento specificato. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyToAsync(Stream, Int32) |
Legge in modo asincrono tutti i byte dal flusso corrente e li scrive in un altro flusso, utilizzando una dimensione di buffer specificata. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyToAsync(Stream, Int32, CancellationToken) |
Legge in modo asincrono i byte dal flusso corrente e li scrive in un altro flusso, usando una dimensione di buffer specificata e un token di annullamento. Entrambe le posizioni dei flussi sono avanzate dal numero di byte copiati. (Ereditato da Stream) |
CopyToAsync(Stream, Int32, CancellationToken) |
Legge in modo asincrono i byte dal flusso di file corrente e li scrive in un altro flusso, usando una dimensione di buffer specificata e un token di annullamento. (Ereditato da FileStream) |
CreateObjRef(Type) |
Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto remoto. (Ereditato da MarshalByRefObject) |
CreateWaitHandle() |
Obsoleti.
Obsoleti.
Obsoleti.
Alloca un oggetto WaitHandle. (Ereditato da Stream) |
Dispose() |
Rilascia tutte le risorse usate da Stream. (Ereditato da Stream) |
Dispose(Boolean) |
Rilascia le risorse non gestite usate da IsolatedStorageFileStream e, facoltativamente, le risorse gestite. |
DisposeAsync() |
Consente di liberare in modo asincrono le risorse non gestite utilizzate da IsolatedStorageFileStream. |
DisposeAsync() |
Consente di liberare in modo asincrono le risorse non gestite utilizzate da Stream. (Ereditato da Stream) |
DisposeAsync() |
Consente di liberare in modo asincrono le risorse non gestite utilizzate da FileStream. (Ereditato da FileStream) |
EndRead(IAsyncResult) |
Termina una richiesta di lettura asincrona in sospeso. |
EndRead(IAsyncResult) |
Attende il completamento della lettura asincrona in sospeso. Si consiglia di usare ReadAsync(Byte[], Int32, Int32). (Ereditato da Stream) |
EndWrite(IAsyncResult) |
Termina una scrittura asincrona. |
EndWrite(IAsyncResult) |
Termina un'operazione di scrittura asincrona. Si consiglia di usare WriteAsync(Byte[], Int32, Int32). (Ereditato da Stream) |
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
Flush() |
Cancella i buffer del flusso e fa sì che i dati memorizzati nel buffer vengano scritti nel file. |
Flush(Boolean) |
Cancella i buffer del flusso e fa sì che i dati memorizzati nei buffer vengano scritti nel file, cancellando anche tutti i buffer di file intermedi. |
Flush(Boolean) |
Cancella i buffer del flusso e fa sì che i dati memorizzati nei buffer vengano scritti nel file, cancellando anche tutti i buffer di file intermedi. (Ereditato da FileStream) |
FlushAsync() |
Cancella in modo asincrono i dati di tutti i buffer del flusso e determina la scrittura dei dati memorizzati nel buffer nel dispositivo sottostante. (Ereditato da Stream) |
FlushAsync(CancellationToken) |
Cancella in modo asincrono i buffer per questo flusso e fa sì che gli eventuali dati memorizzati nel buffer vengano scritti nel file. |
FlushAsync(CancellationToken) |
Cancella in modo asincrono i dati di tutti i buffer del flusso, determina la scrittura dei dati memorizzati nel buffer nel dispositivo sottostante e monitora le richieste di annullamento. (Ereditato da FileStream) |
GetAccessControl() |
Ottiene un oggetto FileSecurity che incapsula le voci dell'elenco di controllo di accesso (ACL) per il file descritto dall'oggetto FileStream corrente. (Ereditato da FileStream) |
GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
GetLifetimeService() |
Obsoleti.
Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza. (Ereditato da MarshalByRefObject) |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
InitializeLifetimeService() |
Obsoleti.
Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
Lock(Int64, Int64) |
Impedisce ad altri processi di leggere o scrivere nel flusso. |
Lock(Int64, Int64) |
Impedisce ad altri processi di leggere o scrivere nell'oggetto FileStream. (Ereditato da FileStream) |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente. (Ereditato da Object) |
MemberwiseClone(Boolean) |
Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente. (Ereditato da MarshalByRefObject) |
ObjectInvariant() |
Obsoleti.
Fornisce supporto per un oggetto Contract. (Ereditato da Stream) |
Read(Byte[], Int32, Int32) |
Copia i byte dall'oggetto IsolatedStorageFileStream attualmente memorizzato nel buffer in una matrice di byte. |
Read(Span<Byte>) |
Copia i byte dall'oggetto IsolatedStorageFileStream attualmente memorizzato nel buffer in un intervallo di byte. |
Read(Span<Byte>) |
Quando ne viene eseguito l'override in una classe derivata, legge una sequenza di byte dal flusso corrente e passa alla posizione successiva all'interno del flusso corrente in base al numero di byte letti. (Ereditato da Stream) |
Read(Span<Byte>) |
Legge una sequenza di byte dal flusso di file corrente e fa avanzare la posizione corrente nel flusso di file del numero di byte letti. (Ereditato da FileStream) |
ReadAsync(Byte[], Int32, Int32) |
Legge in modo asincrono una sequenza di byte dal flusso corrente e passa alla posizione successiva nel flusso in base al numero di byte letti. (Ereditato da Stream) |
ReadAsync(Byte[], Int32, Int32, CancellationToken) |
Copia in modo asincrono i byte dall'oggetto IsolatedStorageFileStream attualmente memorizzato nel buffer in una matrice di byte. |
ReadAsync(Byte[], Int32, Int32, CancellationToken) |
Legge in modo asincrono una sequenza di byte dal flusso di file corrente e li scrive in una matrice di byte a partire da un offset specificato, fa avanzare la posizione all'interno del flusso di file in base al numero di byte letti e monitora le richieste di annullamento. (Ereditato da FileStream) |
ReadAsync(Memory<Byte>, CancellationToken) |
Copia in modo asincrono i byte dall'oggetto IsolatedStorageFileStream attualmente memorizzato nel buffer in un intervallo di memoria in byte. |
ReadAsync(Memory<Byte>, CancellationToken) |
Legge in modo asincrono una sequenza di byte dal flusso corrente e passa alla posizione successiva all'interno del flusso corrente in base al numero di byte letti e monitora le richieste di annullamento. (Ereditato da Stream) |
ReadAsync(Memory<Byte>, CancellationToken) |
Legge in modo asincrono una sequenza di byte dal flusso di file corrente e li scrive in un'area di memoria, fa avanzare la posizione all'interno del flusso di file in base al numero di byte letti e monitora le richieste di annullamento. (Ereditato da FileStream) |
ReadAtLeast(Span<Byte>, Int32, Boolean) |
Legge almeno un numero minimo di byte dal flusso corrente e sposta in avanti la posizione all'interno del flusso in base al numero di byte letti. (Ereditato da Stream) |
ReadAtLeastAsync(Memory<Byte>, Int32, Boolean, CancellationToken) |
Legge in modo asincrono almeno un numero minimo di byte dal flusso corrente, sposta in avanti la posizione all'interno del flusso in base al numero di byte letti e monitora le richieste di annullamento. (Ereditato da Stream) |
ReadByte() |
Legge un singolo byte dall'oggetto IsolatedStorageFileStream nello spazio di memorizzazione isolato. |
ReadExactly(Byte[], Int32, Int32) |
|
ReadExactly(Span<Byte>) |
Legge i byte dal flusso corrente e sposta in avanti la posizione all'interno del flusso fino a quando non viene riempito. |
ReadExactlyAsync(Byte[], Int32, Int32, CancellationToken) |
Legge in modo asincrono |
ReadExactlyAsync(Memory<Byte>, CancellationToken) |
Legge in modo asincrono i byte dal flusso corrente, sposta la posizione all'interno del flusso fino a quando non |
Seek(Int64, SeekOrigin) |
Imposta la posizione corrente di questo oggetto IsolatedStorageFileStream sul valore specificato. |
SetAccessControl(FileSecurity) |
Applica le voci dell'elenco di controllo di accesso (ACL) descritte da un oggetto FileSecurity nel file specificato dall'oggetto FileStream corrente. (Ereditato da FileStream) |
SetLength(Int64) |
Imposta la lunghezza di questo oggetto IsolatedStorageFileStream sul valore |
ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Unlock(Int64, Int64) |
Consente ad altri processi di accedere a una parte o a tutto il file bloccato in precedenza. |
Unlock(Int64, Int64) |
Consente ad altri processi di accedere a una parte o a tutto il file bloccato in precedenza. (Ereditato da FileStream) |
Write(Byte[], Int32, Int32) |
Scrive un blocco di byte nell'oggetto flusso di file di archiviazione isolato usando i dati letti da un buffer costituito da una matrice di byte. |
Write(ReadOnlySpan<Byte>) |
Scrive un blocco di byte nell'oggetto flusso di file di archiviazione isolato usando i dati letti da un buffer costituito da un intervallo di byte di sola lettura. |
Write(ReadOnlySpan<Byte>) |
Quando ne viene eseguito l'override in una classe derivata, scrive una sequenza di byte nel flusso corrente e passa alla posizione successiva all'interno del flusso corrente in base al numero di byte scritti. (Ereditato da Stream) |
Write(ReadOnlySpan<Byte>) |
Scrive una sequenza di byte da un intervallo di sola lettura nel flusso di file corrente e sposta in avanti la posizione nel flusso di file in base al numero di byte scritti. (Ereditato da FileStream) |
WriteAsync(Byte[], Int32, Int32) |
Scrive in modo asincrono una sequenza di byte nel flusso corrente e passa alla posizione successiva nel flusso in base al numero di byte scritti. (Ereditato da Stream) |
WriteAsync(Byte[], Int32, Int32, CancellationToken) |
Scrive in modo asincrono un blocco di byte nell'oggetto flusso di file di archiviazione isolato usando i dati letti da un buffer costituito da una matrice di byte. |
WriteAsync(Byte[], Int32, Int32, CancellationToken) |
Scrive in modo asincrono una sequenza di byte nel flusso corrente e passa alla posizione successiva all'interno del flusso corrente in base al numero di byte scritti e monitora le richieste di annullamento. (Ereditato da FileStream) |
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) |
Scrive in modo asincrono un blocco di byte nell'oggetto flusso di file di archiviazione isolato usando i dati letti da un buffer costituito da un intervallo di memoria di byte di sola lettura. |
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) |
Scrive in modo asincrono una sequenza di byte nel flusso corrente e passa alla posizione successiva all'interno del flusso corrente in base al numero di byte scritti e monitora le richieste di annullamento. (Ereditato da Stream) |
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken) |
Scrive in modo asincrono una sequenza di byte da un'area di memoria nel flusso di file corrente e sposta in avanti la posizione corrente all'interno del flusso di file in base al numero di byte scritti ed esegue il monitoraggio delle richieste di annullamento. (Ereditato da FileStream) |
WriteByte(Byte) |
Scrive un singolo byte nell'oggetto IsolatedStorageFileStream. |
Implementazioni dell'interfaccia esplicita
IDisposable.Dispose() |
Rilascia tutte le risorse usate da Stream. (Ereditato da Stream) |
Metodi di estensione
GetAccessControl(FileStream) |
Restituisce le informazioni di sicurezza di un file. |
SetAccessControl(FileStream, FileSecurity) |
Modifica gli attributi di sicurezza di un file esistente. |
CopyToAsync(Stream, PipeWriter, CancellationToken) |
Legge in modo asincrono i byte da Stream e li scrive nel PipeWriter specificato usando un token di annullamento. |
AsInputStream(Stream) |
Converte un flusso gestito in .NET per app di Windows Store in un flusso di input in Windows Runtime. |
AsOutputStream(Stream) |
Converte un flusso gestito in .NET per app di Windows Store in un flusso di output in Windows Runtime. |
AsRandomAccessStream(Stream) |
Converte il flusso specificato in un flusso di accesso casuale. |
ConfigureAwait(IAsyncDisposable, Boolean) |
Consente di configurare la modalità di esecuzione delle espressioni await per le attività restituite da un elemento disposable asincrono. |
Si applica a
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per