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);
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 5 years ago.
Improve this question
I would like to display the version as yyyy.mm.dd of the last build date to users,
how can I accomplish this? relatively new to c#.
Thanks!
Between HttpContext and System.IO, you can find the location and last modification date of any file within your website
HttpContext (aka Server) has a MapPath() method within it to figure out where you are, and then you can add in the relative location of a particular file.
string AppRoot = HttpContext.Current.Server.MapPath(#"\");
string AppDll = AppRoot + #"bin\MyWebApp.dll";
System.IO can then work with that location to get all of the properties about a particular file. In your context you are looking for the Last Modified Date, and here is a simple method to retrieve it:
public static DateTime GetLastModDate(string FilePath) {
DateTime retDateTime;
if (File.Exists(FilePath)) { retDateTime = File.GetLastWriteTime(FilePath); }
else { retDateTime = new DateTime(0); }
return retDateTime;
}
Combine these and you get
DateTime LastBuildDate = GetLastModDate(AppDll);
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 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
I found application that use .txt files as config files.
The Files looks like
[[plugin.save]]=[[Save]]
how do I use it in C#?
how can I read The file to my application to use Values in [] as config?
You have to read it as a regular file. Reading it use Dictionary to store values.
Example code:
Dictionary<string, string> configuration = new Dictionary<string, string>();
Regex r = new Regex(#"\[\[(\w+)\]\]=\[\[(\w+)\]\]");
string[] configArray = {"[[param1]]=[[Value1]]", "[[param2]]=[[Value2]]"};// File.ReadAllLines("some.txt");
foreach (string config in configArray)
{
Match m = r.Match(config);
configuration.Add(m.Groups[1].Value, m.Groups[2].Value);
}
Please note to check for possible null values.
Note also that regex expression should be different if config values can contain for example spaces.
Just use:
var config = File.ReadAllLines(FileLocation)
And then parse it with the
String.Split()
Might use regex as well.
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
I have HashSet> collection. I want to display content of this HashSet in richTextBox ? How to convert this HashSet to right type ?
Try :
richTextBox.Text = string.Join("", yourSet.ToArray());
try this instead:
foreach (SortedSet<string> set in youHashSet)
{
richTextBox.Text = string.Join("", set.ToArray());
}
Well a little bit of more information would have helped. It's hard to say without seeing your code. But these are your basic steps
after you build your Hashset
then for a for or foreach loop on it
and then ToString the object if it's not a Hashset
string helloWorld = string.empty;
foreach(<whateverobject> myobject in Hashset<whateverobject> myHashsetList)
{
helloWorld = helloWorld = myobject.ToString();
}
richTextBox.Text = helloWorld;
If you delimit it or whatever that's up to you
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"]);