What is IsolatedStorageFileStream? [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In examples on how to use IsolatedStorage I have found two main techniques:
var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (var writer = new StreamWriter(appStorage.CreateFile("fileName", FileMode.Create, FileAccess.Write)))
{
writer.WriteLine("Text");
writer.Close()
}
And the other:
var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("fileName", FileMode.Create, FileAccess.Write, appStorage)))
{
writeFile.WriteLine("Text");
writeFile.Close();
}
My question is: Is there any real difference between these two techniques?
As well as: Is either method usually preffered by developers? Or is it just down to personal Opinion?

IsolatedStorageFile is essentially a pointer to the isolated storage file (area) on disk.
IsolatedStorageFileStream is an in-memory representation of the data in a file within the isolated storage area.

Related

How can I programmatically save a RDLC file to open in future [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Im doing my first project with C# and I need my program automatically save a RDLC file to re-open it, with the data, when requisited. It's a "Receipt Report" that I need to keep stored. What the best way to do this?
The solution should be pretty straight forward, you should be able to get what you need through Google search...
You may reference the following code and expand on it.
string strmimeType = "", encoding, fileNameExtension = "";
string[] streamIds;
Warning[] warning;
//Other Code Here...
byte[] bytes = ReportViewer.LocalReport.Render("PDF", null, out strmimeType, out encoding, out fileNameExtension, out streamIds, out warning);
//Save to file
string filePath = #"C:\someTempFolder\temp" + fileNameExtension;
FileStream FileObject = new FileStream(filePath, FileMode.Create, FileAccess.Write);
FileObject.Write(bytes, 0, bytes.Length);
FileObject.Close();

How to download files from Google Cloud Storage [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this working code which read and print out a list of file name from Google Bucket in C#.
GoogleCredential credential = null;
using (var jsonStream = new FileStream(#"D:\data.json", FileMode.Open,
FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(jsonStream);
}
var storageClient = StorageClient.Create(credential);
// List objects
foreach (var obj in storageClient.ListObjects(bucketName, ""))
{
Console.WriteLine(obj.Name);
}
My question is how to I auto download this list of files into my computer?
I managed to solve it by using DownloadObject method from StorageClient object.

C# How to create a zip file from 3 directory contents [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
pseudo code:
c:\temp\Backup.zip = (c:\Temp\Config*.* , c:\Temp\Data*., c:\Temp\scripts*.)
Thanks in Advance!
Try DotNetZip library. DotNetZip
Here is a very simple example:
ZipFile zipFile = new ZipFile();
zipFile.AddFile("{path}/file.txt");
zipFile.Save("{path}/filename.zip");
zipFile.Dispose();
For doing this with files in a directory you can use
string [] files = Directory.GetFiles("directoryPath", "*.txt");
And add to zipFile instance each file in the array. Notice: Second parameter in Directory.GetFiles function is the search pattern

Streamreader Directory [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm working with StreamReader in my Asp.Net mvc application.
I'm having an issue getting the StreamReader to use the root of my application, and not the C:// drive on my machine.
I have the following:
public ActionResult Test()
{
XmlSerializer serializer = new XmlSerializer(typeof(Test));
TextReader textReader;
textReader = new StreamReader("../Content/items.xml");
Test test = (Test)serializer.Deserialize(textReader);
textReader.Close();
return View(test);
}
When you run a web application, the current working directory of the process isn't the directory containing your source code. You might want to look at HttpServerUtility.MapPath or HostingEnvironment.MapPath.
Note that this doesn't really have anything to do with StreamReader - for diagnostic purposes, you'd be better off with something like:
FileInfo file = new FileInfo("../Content/items.xml");
Debug.WriteLine(file.FullName);

FileStream Vs System.IO.File.WriteAllText when writing to files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have seen many examples/ tutorials about VB.NET or C#.NET where the author is using a FileStream to write/read from a file. My question is there any benefit to this method rather than using System.IO.File.Read/Write ? Why are the majority of examples using FileStream to when the same can be achieved using just a single line of code?
FileStream gives you a little more control over writing files, which can be beneficial in certain cases. It also allows you to keep the file handle open and continuously write data without relinquishing control. Some use cases for a stream:
Multiple inputs
Real time data from a memory/network stream.
System.IO.File contains wrappers around file operations for basic actions such as saving a file, reading a file to lines, etc. It's simply an abstraction over FileStream.
From the .NET source code here is what WriteAllText does internally:
private static void InternalWriteAllText(string path,
string contents, Encoding encoding)
{
Contract.Requires(path != null);
Contract.Requires(encoding != null);
Contract.Requires(path.Length > 0);
using (StreamWriter sw = new StreamWriter(path, false, encoding))
sw.Write(contents);
}

Categories