本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFileStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFileStream.Write方法的具体用法?C# IsolatedStorageFileStream.Write怎么用?C# IsolatedStorageFileStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.IsolatedStorage.IsolatedStorageFileStream
的用法示例。
在下文中一共展示了IsolatedStorageFileStream.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: wc_OpenReadCompleted
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
string iconPath = "1.txt";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
var isfs = new IsolatedStorageFileStream(iconPath, FileMode.Create, isf);
int bytesRead;
byte[] bytes = new byte[e.Result.Length];
while ((bytesRead = e.Result.Read(bytes, 0, bytes.Length)) != 0)
{
isfs.Write(bytes, 0, bytesRead);
}
isfs.Flush();
isfs.Close();
}
this.Dispatcher.BeginInvoke(() =>
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
}
示例2: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog nekaj = new OpenFileDialog();
bool? nekaj2 = nekaj.ShowDialog();
if (nekaj2 == true)
{
using (FileStream fs = nekaj.File.OpenRead())
{
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
char[] niz = new char[buffer.Length];
for (int i = 0; i < buffer.Length; i++)
niz[i] = (char)buffer[i];
IsolatedStorageFile isf =
IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream tok = new IsolatedStorageFileStream("test.txt", FileMode.Create, isf);
tok.Write(buffer, 0, buffer.Length);
tok.Close();
}
}
else MessageBox.Show("Preklicano");
}
示例3: SaveFile
public static void SaveFile (string fileName)
{
fileName += ".wav";
// first, we grab the current apps isolated storage handle
var storage = IsolatedStorageFile.GetUserStoreForApplication ();
// if that file exists...
if (storage.FileExists (fileName))
{
// then delete it
storage.DeleteFile (fileName);
}
// now we set up an isolated storage stream to point to store our data
var stream = new IsolatedStorageFileStream (fileName, FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication ());
var streamArray = Utilities.MemoryStream.ToArray ();
stream.Write (streamArray, 0, streamArray.Length);
// ok, done with isolated storage... so close it
stream.Close ();
Utilities.MemoryStream = null;
}
示例4: RestoreFromFile
private void RestoreFromFile(Stream file)
{
//
//
using (var store = IsolatedStorageFile.GetUserStoreForApplication()) {
using (var zip = new ZipInputStream(file)) {
try {
while (true) {
var ze = zip.GetNextEntry();
if (ze == null) break;
using (var f = new IsolatedStorageFileStream(ze.Name, FileMode.Create, store)) {
var fs = new byte[ze.Size];
zip.Read(fs, 0, fs.Length);
f.Write(fs, 0, fs.Length);
}
}
} catch {
lblLastBackup.Text = StringResources.BackupAndRestorePage_Messages_RestoreFailed;
App.ToastMe(StringResources.BackupAndRestorePage_Messages_RestoreFailed);
return;
} finally {
file.Close();
ClearOldBackupFiles();
App.ViewModel.IsRvDataChanged = true;
}
}
}
lblLastBackup.Text = StringResources.BackupAndRestorePage_Messages_RestoreSuccess;
App.ToastMe(StringResources.BackupAndRestorePage_Messages_RestoreSuccess);
}
示例5: MakeFile
/// <summary>
/// Create a file in IsolatedStorage.
/// </summary>
/// <param name="data">The data you want to write, expressed as a byte array.</param>
/// <param name="filepath">The path of the file you want to write.</param>
/// <param name="storage">A reference to a valid IsolatedStorageFile instance.</param>
public static void MakeFile(byte[] data, string filepath, IsolatedStorageFile storage)
{
CreateDirectoryTree(filepath, storage);
using (var filestream = new IsolatedStorageFileStream(filepath, FileMode.Create, FileAccess.Write, storage))
{
filestream.Write(data, 0, data.Count());
}
}
示例6: WriteAllText
public static void WriteAllText(string fileName, string content)
{
var data = Encoding.UTF8.GetBytes(content);
using (var folder = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write, folder))
stream.Write(data, 0, data.Length);
}
}
示例7: SaveToIsolatedStorage
public static void SaveToIsolatedStorage(string key, string value)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, typeof(System.Security.Policy.Url), typeof(System.Security.Policy.Url)))
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(key + ".txt", FileMode.Create, isf))
{
byte[] data = System.Text.Encoding.UTF8.GetBytes(value);
isfs.Write(data, 0, data.Length);
}
}
}
示例8: WriteToIsolatedStorage
/// <summary>
/// Writes byte data to an isolated storage file.
/// </summary>
/// <param name="data">The bytes to write to the file.</param>
/// <param name="path">Path to the file.</param>
public static void WriteToIsolatedStorage(byte[] data, string path)
{
// Create a file in the application's isolated storage.
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream writestream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, file))
{
writestream.Write(data, 0, data.Length);
}
}
}
示例9: SerializeObject
public static void SerializeObject(string filename, object obj)
{
//Stream stream = File.Open(filename, FileMode.Create);
IsolatedStorageFile isof = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(filename, FileMode.Create, isof);
byte[] b = BusinessLib.SilverlightSerializer.Serialize(obj);
isfs.Write(b, 0, b.Length);
isfs.Flush();
isfs.Close();
isof.Dispose();
}
示例10: WriteFile
public static bool WriteFile(string filename,string data)
{
bool success = false;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream filestream = new IsolatedStorageFileStream(filename, System.IO.FileMode.Create, isf);
byte[] buffer = Encoding.UTF8.GetBytes(data);
filestream.Write(buffer, 0, buffer.Length);
filestream.Close();
success = true;
}
return success;
}
示例11: CopyFileFromXAP
/// <summary>
/// Copy file from the XAP to the isolated storage
/// </summary>
/// <param name="sourceFileName"></param>
/// <param name="destinationFileName"></param>
public static void CopyFileFromXAP(string sourceFileName, string destinationFileName)
{
//TODO: 10/8 Handle Errors
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
if (!isf.FileExists(destinationFileName))
{
BinaryReader fileReader = new BinaryReader(Application.GetResourceStream(new Uri(sourceFileName, UriKind.Relative)).Stream);
//Increase Isolated Storage Quota If needed
bool checkQuotaIncrease = FilesManager.CanIsolatedStorageSpaceSizeIncrease(fileReader.BaseStream.Length);
IsolatedStorageFileStream outFile = new IsolatedStorageFileStream(destinationFileName, FileMode.Create, isf);
bool eof = false;
long fileLength = fileReader.BaseStream.Length;
int writeLength = 512;
while (!eof)
{
if (fileLength < 512)
{
writeLength = Convert.ToInt32(fileLength);
outFile.Write(fileReader.ReadBytes(writeLength), 0, writeLength);
}
else
{
outFile.Write(fileReader.ReadBytes(writeLength), 0, writeLength);
}
fileLength = fileLength - 512;
if (fileLength <= 0) eof = true;
}
fileReader.Close();
outFile.Close();
}
}
示例12: CacheImage
public void CacheImage(string imageFileName, Stream imageStream)
{
using (var output = new IsolatedStorageFileStream(imageFileName, FileMode.Create, GetIsolatedStorageFile()))
{
var buffer = new byte[1024];
int read;
if (imageStream != null)
while ((read = imageStream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
}
示例13: WriteFeedToIsolatedStorage
public static void WriteFeedToIsolatedStorage(string feedxml, Uri feedUri)
{
using(var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
CreateDirectoryTree(feedUri, storage);
using(var filestream = new IsolatedStorageFileStream(feedUri.OriginalString, FileMode.Create, FileAccess.Write, storage))
{
var data = Encoding.UTF8.GetBytes(feedxml);
filestream.Write(data, 0, data.Count());
}
}
}
示例14: MainViewModel
/// <summary>
/// Initializes a new instance of the <see cref="MainViewModel" /> class.
/// </summary>
public MainViewModel()
{
IsRvDataChanged = true;
lbRvItems = new ObservableCollection<ReturnVisitSummaryModel>();
lbMainMenuItems = new ObservableCollection<MainMenuModel>();
RvSearchBoxSuggestionsSource = new ObservableCollection<ReturnVisitSummaryModel>();
RvSearchBoxLoaded = false;
if (!IsolatedStorageFile.GetUserStoreForApplication().FileExists("mainpage.xml")) {
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) {
using (var file = new IsolatedStorageFileStream("mainpage.xml", FileMode.CreateNew, iso)) {
byte[] b = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"utf-8\" ?><items><magazines>0</magazines><brochures>0</brochures><books>0</books><rvs>0</rvs><bs>0</bs><tracts>0</tracts><notes> </notes></items>");
file.Write(b, 0, b.Length);
}
}
}
}
示例15: CopyFromContentToStorage
public static void CopyFromContentToStorage(String sourceFile, String destinationFile)
{
IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
using (Stream inputStream = Application.GetResourceStream(new Uri(sourceFile, UriKind.Relative)).Stream)
{
using (IsolatedStorageFileStream outStream = new IsolatedStorageFileStream(destinationFile, FileMode.Create, FileAccess.Write, isolatedStorageFile))
{
Byte[] Buffer = new Byte[5120];
Int32 ReadCount = inputStream.Read(Buffer, 0, Buffer.Length);
while (ReadCount > 0)
{
outStream.Write(Buffer, 0, ReadCount);
ReadCount = inputStream.Read(Buffer, 0, Buffer.Length);
}
}
}
}