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);
Related
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.
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
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 7 years ago.
Improve this question
How to pretend to have a file without actually loading a file? The challenge is not to create a temporary file or load anything from a harddrive. I would rather like to keep everything in "memory".
In memory means to me having an existing class which derivates from stream initalized and having that class working like it loaded a file from harddrive but it didnt...
A memory stream isn't a file. It's just data. The concept of setting a filename and extension on a memory stream simply doesn't make sense - any more than it would for a byte[].
You can create a subclass to keep track of the filename, like so
class MemoryStreamWithFile: MemoryStream
{
public string Filename { get; set; }
}
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 have a URL, such as http://www.mydomain.com/?param1=asd2¶m2=asd2.
I'd like to create a sort of Frequest object, so than I can easily do somethings like:
Request.Querystring("param1")
without do a further Split and access to the array. Can I?
Your question is not clear. Are you looking something like this?
var uri = new Uri("http://www.mydomain.com/?param1=asd2¶m2=asd2");
var nv = uri.ParseQueryString();
Console.WriteLine(nv["param1"]);
EDIT
It seams one of my referenced libraries implemented this extension Method. Anyway, it can be done as
var uri = new Uri("http://www.mydomain.com/?param1=asd2¶m2=asd2");
var nv = HttpUtility.ParseQueryString(uri.Query);
Console.WriteLine(nv["param1"]);
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 9 years ago.
Improve this question
I have a lot of txt files in Resources folder. One of them is corner.txt. I can access this file via this code snippet:
Properties.Resources.corner
I keep file names in string variables. For example:
string fileName = "corner.txt";
I want to access this file via:
Properties.Resources.fileName
Is this possible? How can I access?
I solved the problem this code snippet:
string st = Properties.Resources.ResourceManager.GetString(tableName);
So, I don't use the filename, I use the txt file's string. This is useful for me.
Thanks a lot.
You can use Reflection like that:
var type = typeof(Properties.Resources);
var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public);
var value = property.GetValue(null, null);
or use the ResourceManager like that:
value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture);